#!/usr/bin/perl use Benchmark qw(cmpthese); my $test_text = q|Wow, that was quick!
Two points:
1) I only want space, not tabs or new lines - so shouldn't the \s be replaced with " "?
2) Is there a difference between inkgmi's and GrandFather's entry?
PS I thought executed regexs are experimental (so says the man page) - is there a problem with them?
|; my $working_var; my $count = 1000000; cmpthese($count, { 'grandfather' => sub {$working_var = $test_text; $working_var =~ s/ ( +)/" " . (" " x length ($1))/ge}, 'ikegami' => sub {$working_var = $test_text; $working_var =~ s/(?<= )( )/' ' x length($1)/eg} }); __OUTPUT__ Benchmark: timing 1000000 iterations of grandfather, ikegami... grandfather: 31 wallclock secs (31.01 usr + 0.00 sys = 31.01 CPU) @ 32252.86/s (n=1000000) ikegami: 52 wallclock secs (51.26 usr + 0.00 sys = 51.26 CPU) @ 19506.87/s (n=1000000) Rate ikegami grandfather ikegami 19507/s -- -40% grandfather 32253/s 65% --