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

Re^2: perl process slower and slower when loop number increase

by Anonymous Monk
on Jan 22, 2018 at 12:05 UTC ( [id://1207661]=note: print w/replies, xml ) Need Help??


in reply to Re: perl process slower and slower when loop number increase
in thread perl process slower and slower when loop number increase

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

Replies are listed 'Best First'.
Re^3: perl process slower and slower when loop number increase
by Dallaylaen (Chaplain) on Jan 22, 2018 at 15:59 UTC
    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1207661]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-24 20:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found