$10K coding deathmatch

Andy Bradford amb-plug at bradfords.org
Fri Nov 3 10:38:37 MST 2006

Thus said Paul Seamons on Fri, 03 Nov 2006 08:27:09 MST:

> Though I love seeing perl appear  to be faster, you really would need 
> to change the benchmark to iterate over the actual test a bit more so 
> you could  even out the CPU  time attributed to startup.  Perhaps you 
> did.                                                                  

I  actually didn't,  and  in fact  mentioned that  the  test sample  was
probably too small. I retested by  duplicating the 5 lines 100 times and
then ran each again (except PHP):

My Tcl version:

real    0m0.148s
user    0m0.133s
sys     0m0.008s

Python version:

real    0m0.064s
user    0m0.047s
sys     0m0.008s

Michael's Tcl version:

real    0m0.050s
user    0m0.047s
sys     0m0.000s

perl -ape '$_=((grep{(abs($F[$_]-$F[$_-1])||@F)>=@F}1..$#F)?"not a":"")."match\n"'

real    0m0.027s
user    0m0.016s
sys     0m0.008s

perl -ape '$_="match\n";$i=0;while(++$i<@F){lastif(abs$F[$i]-$F[$i-1]||@F)>=@F and $_="not a $_"}'

real    0m0.012s
user    0m0.008s
sys     0m0.008s

Looks like the short circuit Perl was indeed faster after all.

[-----------[system uptime]--------------------------------------------]
 10:38am  up 5 days, 23 min,  1 user,  load average: 1.00, 1.00, 1.00

More information about the PLUG mailing list