This must be OS dependent or something... (hard to say as you didnt post the output). On my system print with no cache is much faster:
open my $zap, ">", "NULL:"; use Benchmark "cmpthese"; cmpthese -10, { every => sub { for (1..100) { print $zap $_ } }, tens => sub { my $x; for (1..100) { $x .= $_; unless ($x % 10) { print $zap $x; $x=""; } } print $zap $x if length $x; }, } __END__ # modfied code as posted above (5.6.1 on W2k) Rate tens every tens 1159/s -- -90% every 11285/s 874% -- # original code (5.6.1 on W2k) Rate tens every tens 1124/s -- -90% every 11219/s 899% -- # 5.8.4 (XP) Rate tens every tens 8305/s -- -73% every 30329/s 265% -- # 5.8.6 No Implicit Sys (XP) Rate tens every tens 9655/s -- -68% every 29755/s 208% --
At least on Win32 it would seem just using print is much faster.... I guess this could be an example of what Steve Hay was talking about with Win32's realloc being crap and that it makes concatenation unecessarily slow. Update: No, that doesnt make sense, I just tried it with two different perl versions on two different win32 boxes and "every" won every one of them....
Ignore this for now, its got a bug: "NUL" not "NULL:",as ysth pointed out. Ill redo it when i have access to all those perl versions again
In reply to Re^4: perl performance vs egrep
by demerphq
in thread perl performance vs egrep
by dba
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |