in reply to Re^5: split command
in thread split command
use strict; use warnings; use Benchmark q{cmpthese}; my $rsIndex = sub { my $str = q{MYKEY=MYVAL=2}; my $pos = index $str, q{=}; my $key = substr $str, 0, $pos; my $val = substr $str, $pos + 1; return [$key, $val]; }; my $rsMatch = sub { my ($key, $val) = q{MYKEY=MYVAL=2} =~ /^([^=]*)=(.*)/s; return [$key, $val]; }; my $rsSplit = sub { my ($key, $val) = split m{=(?=.*=)}, q{MYKEY=MYVAL=2}; return [$key, $val]; }; cmpthese(-5, { Index => $rsIndex, Match => $rsMatch, Split => $rsSplit });
Rate Split Match Index Split 26498/s -- -6% -33% Match 28068/s 6% -- -29% Index 39627/s 50% 41% --
Cheers,
JohnGG
|
|---|