#!/usr/bin/perl
use strict;
use warnings;
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?
|;
####
cmpthese(-3, {
GrandFather => sub {
local $_ = $test_text;
scalar s/ ( +)/" " . (" " x length ($1))/ge
},
ikegami => sub {
local $_ = $test_text;
scalar s/(?<= )( +)/' ' x length($1)/eg
},
Smylers => sub {
local $_ = $test_text;
scalar s/(?<= )( )/ /g
},
});
__END__
Rate ikegami Smylers GrandFather
ikegami 22180/s -- -25% -31%
Smylers 29772/s 34% -- -8%
GrandFather 32268/s 45% 8% --