Skip to content

anonymous /gist:5978996
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/usr/bin/perl
use Benchmark qw( cmpthese );
sub nostcmp {
my ($a_char, $a_num) = split '_', $a;
my ($b_char, $b_num) = split '_', $b;
return $a_char cmp $b_char
||
$a_num <=> $b_num;
}
sub nost {
return sort nostcmp @_;
}
sub st {
return
map $_->[0],
sort { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2] }
map [ $_, split /_/ ],
@_;
}
my %tests = (
nost => 'my @sorted = nost(@list);',
st => 'my @sorted = st(@list);',
);
$_ = 'use strict; use warnings; our @list; ' . $_
for values %tests;
{
local our @list = qw(B_5 A_11 C_0 A_10 A_1);
cmpthese(-3, \%tests);
}
{
local our @list = qw(B_5 A_11 C_0 A_10 A_1);
@lists = (@lists)x100;
cmpthese(-3, \%tests);
}
__END__
Rate st nost
st 92589/s -- -7%
nost 99653/s 8% --
Rate st nost
st 93349/s -- -6%
nost 99817/s 7% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.