Even slower than the s/// suggestion.
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw 'cmpthese';
our @dates = (qw [092205 092305 092605]) x 100;
our (@sub, @pck, @mth, @spf,);
cmpthese(-10, {
sub => '@sub = @dates; for (@sub) {s{(\d{2})(\d{2})(\d{2})}{$1/$2/
+$3}}',
pck => '@pck = @dates; for (@pck) {$_ = join "/", unpack "A2 A2 A2
+", $_}',
mth => '@mth = @dates; for (@mth) {$_ = join "/", /../g}',
spf => '@spf = @dates; for (@spf) {$_ = sprintf "%d%d/%d%d/%d%d",
+split //}',
});
__END__
Rate spf sub mth pck
spf 368/s -- -33% -60% -69%
sub 548/s 49% -- -40% -53%
mth 909/s 147% 66% -- -22%
pck 1171/s 218% 114% 29% --
|