The total execution time is startup_time + count * iteration_time. For numbers like 10..10000 the loop time is negligible compared to reading the interpreter from disk, parsing script etc.
You can eliminate the startup time (assuming it's constant) by running several different big (10**6+) loops, then plotting time against count:
bash$ for i in `seq 10`; do echo $i; time perl -e 'for($i=0;$i<='$i'*1 +000000 ;$i++){}'; done 1 real 0m0.055s user 0m0.048s sys 0m0.000s 2 real 0m0.051s user 0m0.048s sys 0m0.000s 3 real 0m0.074s user 0m0.068s sys 0m0.000s 4 real 0m0.099s user 0m0.088s sys 0m0.004s 5 real 0m0.124s user 0m0.116s sys 0m0.000s 6 real 0m0.146s user 0m0.140s sys 0m0.000s 7 real 0m0.166s user 0m0.164s sys 0m0.000s 8 real 0m0.197s user 0m0.184s sys 0m0.000s 9 real 0m0.217s user 0m0.204s sys 0m0.004s 10 real 0m0.235s user 0m0.232s sys 0m0.000s bash$ for i in `seq 10`; do echo $i; time php -r 'for($i=0;$i<='$i'*10 +00000 ;$i++){}'; done 1 real 0m0.034s user 0m0.020s sys 0m0.012s 2 real 0m0.036s user 0m0.028s sys 0m0.000s 3 real 0m0.035s user 0m0.032s sys 0m0.000s 4 real 0m0.040s user 0m0.036s sys 0m0.000s 5 real 0m0.048s user 0m0.040s sys 0m0.004s 6 real 0m0.055s user 0m0.052s sys 0m0.000s 7 real 0m0.065s user 0m0.060s sys 0m0.000s 8 real 0m0.071s user 0m0.068s sys 0m0.000s 9 real 0m0.080s user 0m0.076s sys 0m0.000s 10 real 0m0.087s user 0m0.084s sys 0m0.000s
What surprises me here is that PHP is much faster than Perl.
In reply to Re: perl process slower and slower when loop number increase
by Dallaylaen
in thread perl process slower and slower when loop number increase
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |