Created
February 24, 2018 10:39
-
-
Save haukex/eeebfdaf0951e32be4d0cb5eee3e982d 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
use warnings; | |
use strict; | |
use Benchmark qw/cmpthese/; | |
for my $r (10,100,1_000,10_000) { | |
print " ___ $r ___\n"; | |
my $str = "foo;bar;" x $r; | |
cmpthese(-1, { | |
orig => sub { # https://stackoverflow.com/q/48961457/9300627 | |
$str=~s/\b([^;]+)(?=.*;\1;);//gr; | |
}, | |
revo => sub { # https://stackoverflow.com/a/48961672/9300627 | |
$str=~s/(?<![^;])([^;]++;)(?=(?>[^;]*;)*?\1)//gr; | |
}, | |
split => sub { # https://stackoverflow.com/a/48961541/9300627 | |
my %seen; | |
join ';', grep { !$seen{$_}++ } split /;/, $str; | |
}, | |
}); | |
} | |
__END__ | |
___ 10 ___ | |
Rate revo orig split | |
revo 142174/s -- -8% -64% | |
orig 154984/s 9% -- -61% | |
split 398221/s 180% 157% -- | |
___ 100 ___ | |
Rate orig revo split | |
orig 11294/s -- -22% -77% | |
revo 14499/s 28% -- -70% | |
split 48762/s 332% 236% -- | |
___ 1000 ___ | |
Rate orig revo split | |
orig 316/s -- -80% -94% | |
revo 1614/s 411% -- -69% | |
split 5288/s 1573% 228% -- | |
___ 10000 ___ | |
Rate orig revo split | |
orig 3.88/s -- -98% -99% | |
revo 160/s 4020% -- -70% | |
split 532/s 13609% 233% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment