Created
January 25, 2012 04:51
-
-
Save vitaminmoo/1674789 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Benchmark qw(:all); | |
$a = "foo[bar]moo"; | |
cmpthese( | |
10000000, { | |
capture => sub { | |
$a =~ /\[(\w)\]/; | |
$1; | |
}, | |
zerowidth => sub { | |
$a =~ /(?<=\[)(\d+)(?=\])/; | |
$1; | |
}, | |
split => sub{ | |
$b = (split( /\[|\]/, $a))[1]; | |
$b; | |
}, | |
twosplit => sub{ | |
$b = (split( /\[/, (split( /\]/, $a ))[0]))[1]; | |
$b; | |
}, | |
} | |
); | |
__END__ | |
Rate split twosplit capture zerowidth | |
split 233209/s -- -58% -84% -85% | |
twosplit 559597/s 140% -- -61% -64% | |
capture 1428571/s 513% 155% -- -7% | |
zerowidth 1536098/s 559% 175% 8% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment