Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: perl process slower and slower when loop number increase

by QM (Parson)
on Jan 22, 2018 at 11:23 UTC ( #1207657=note: print w/replies, xml ) Need Help??


in reply to perl process slower and slower when loop number increase

Running the tests like that mixes in the results of startup time with loop time. Use a real benchmark module to time the actual code, and time per iteration. If you want to count the startup time, do that too, with a loop around multiple startups.

There are probably other issues with this. Get some benchmarking wisdom to make sure you're not doing something awful.

But the killer is, You're not doing anything productive, just counting useless loops -- so all of the time is wasted on bookkeeping!

-QM
--
Quantum Mechanics: The dreams stuff is made of

  • Comment on Re: perl process slower and slower when loop number increase

Replies are listed 'Best First'.
Re^2: perl process slower and slower when loop number increase
by karlgoethebier (Abbot) on Jan 22, 2018 at 16:02 UTC
    "... Use a real benchmark module to time..."

    Yes sure - this is true. But i wonder what a serious way might be to get robust results in this case.

    Just an idea: What about IPC::Run? Building the harnesses for each command (Perl, PHP) and then calling run for each harness with Benchmark?

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re^2: perl process slower and slower when loop number increase
by Anonymous Monk on Jan 22, 2018 at 12:05 UTC
    you can count startup time like this, just do nothing:
    $ time perl -e '' real 0m0.003s user 0m0.000s sys 0m0.000s $ time php -r '' real 0m0.023s user 0m0.020s sys 0m0.000s

    perl always have faster startup time

    but if using $i = 100000000 where perl 7secs vs PHP 1.6secs, then the problem is not startup time

    the "problem" is on perl loop, or there limit of the loop number that perl "want" to handle, thats why, I try to ask how to set the loop limit. (maybe system limit or some ENV)

    note: this varian loop have same result $ time perl -e 'for($i=0;$i<=1000;$i++){for($j=0;$j<=1000;$j++){for($k +=0;$k<=100;$k++){}}}' real 0m7.867s user 0m7.860s sys 0m0.000s $ time php -r 'for($i=0;$i<=1000;$i++){for($j=0;$j<=1000;$j++){for($k= +0;$k<=100;$k++){}}}' real 0m1.717s user 0m1.712s sys 0m0.000s

    in my vps, seem the limit is about 100k, beyond this, perl start slowing

    note: if we not include startup time at above code, at 100k PHP and Perl have almost similiar performance $ time perl -e 'for($i=0;$i<=100000;$i++){}' real 0m0.010s user 0m0.008s sys 0m0.000s $ time php -r 'for($i=0;$i<=100000;$i++){}' real 0m0.030s user 0m0.016s sys 0m0.012s
      for ($i=0; $i<1; $i++); is a better null statement because the parsing time would be exactly the same. And running 1 iteration of a loop (or 100 for that matter) is negligible.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1207657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2021-04-12 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?