Apparently, the substr is just too efficient compared to regex. End the print is only a bit inefficient compared to storing stuff in memory.use Benchmark; undef $/; open DATA, "/home/jeroen/texs/review/reviewnew.tex" or die $!; #just s +ome lengthy manuscript $str = <DATA>; open DUMP, ">/dev/null"; timethese( -1, {'regex' => sub { $a = $str; print DUMP map "$_\n", $a=~/\G(.{1,80})/gs; }, 'substr' => sub { $a = $str; $b=''; $b .= substr( $a, 0, 80, '')."\n" while length($a) >80; print DUMP "$b$a"; } }); #givesBenchmark: running regex, substr, each for at least 1 CPU second +s... regex: 1 wallclock secs ( 1.05 usr + 0.01 sys = 1.06 CPU) @ 28 +7.74/s (n=305) substr: 1 wallclock secs ( 1.26 usr + 0.01 sys = 1.27 CPU) @ 55 +6.69/s (n=707) #This changes a bit when leaving the map out: Benchmark: running regex, substr, each for at least 1 CPU seconds... regex: 2 wallclock secs ( 1.06 usr + 0.00 sys = 1.06 CPU) @ 39 +6.23/s (n=420) substr: 2 wallclock secs ( 1.04 usr + 0.02 sys = 1.06 CPU) @ 54 +7.17/s (n=580) #I left the print out@substr at first (didn't want to test # print), but putting it back in gives: Benchmark: running regex, substr, each for at least 1 CPU seconds... regex: 1 wallclock secs ( 1.30 usr + 0.01 sys = 1.31 CPU) @ 36 +6.41/s (n=480) substr: 1 wallclock secs ( 1.06 usr + 0.02 sys = 1.08 CPU) @ 47 +3.15/s (n=511) #I added a better comparison: Rate regmap regex fixreg substr regmap 285/s -- -19% -22% -56% regex 350/s 23% -- -4% -46% fixreg 364/s 28% 4% -- -44% substr 650/s 128% 86% 78% --
Jeroen
"We are not alone"(FZ)
In reply to Re:{4} how do I line-wrap while copying to stdout?
by jeroenes
in thread how do I line-wrap while copying to stdout?
by ams
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |