Subject: | String::Replace::Safe is faster than String::Replace |
I am not sure that your statement that String::Replace is faster than String::Replace::Fast is always true. In fact, using the sample parameters from your Pod and the benchmark script below, I always get faster results for the safe version. I tried perl 5.12.x .. 5.18.0 on Debian Linux and FreeBSD.
Regards,
Slaven
#!/usr/bin/perl
use strict;
use String::Replace ();
use String::Replace::Safe ();
use Benchmark qw(cmpthese);
use Test::More 'no_plan';
my @args = ('this is a string', 'this' => 'that', 'string' => 'chair');
my $unsafe = sub {
String::Replace::replace(@args);
};
my $safe = sub {
String::Replace::Safe::replace(@args);
};
is $safe->(), $unsafe->();
is $safe->(), 'that is a chair';
cmpthese(-1, {
'unsafe' => $unsafe,
'safe' => $safe,
});
__END__