Interesting to note that you need to be sorting thousands of items before the GRT starts to show benefit over a plain sort.
It's better than the ST though, which looks to require millions before it gains anything.
#! perl -slw
use strict;
use Benchmark qw[ cmpthese ];
my @prefixes = 'AA' .. 'ZZ';
my @suffixes = '00' .. '99';
our $N //= 10;
our @data = map{
'AA-'
. $prefixes[ rand @prefixes ]
. $suffixes[ rand @suffixes ]
. '-XX'
} 1 .. $N;
cmpthese -3, {
buk => q[
my @sorted = sort{
substr( $a, 3, 4, ) cmp substr( $b, 3, 4 )
} @data
],
GF => q[
my @sorted = map {
$_->[0]
} sort {
$a->[2] cmp $b->[2]
} map {
[$_, split '-']
} @data
],
jfn => q[
my @sorted = map {
substr $_, 4
} sort map {
substr($_, 3, 4) . $_
} @data
],
};
__END__
c:\test>903885
Rate GF jfn buk
GF 18332/s -- -61% -79%
jfn 46452/s 153% -- -47%
buk 88418/s 382% 90% --
c:\test>903885 -N=100
Rate GF jfn buk
GF 1584/s -- -64% -67%
jfn 4394/s 177% -- -8%
buk 4757/s 200% 8% --
c:\test>903885 -N=1000
Rate GF buk jfn
GF 118/s -- -64% -69%
buk 333/s 181% -- -14%
jfn 387/s 227% 16% --
c:\test>903885 -N=10000
Rate GF buk jfn
GF 8.86/s -- -61% -76%
buk 22.8/s 157% -- -38%
jfn 36.7/s 314% 61% --
c:\test>903885 -N=100000
(warning: too few ite
Rate GF buk jfn
GF 0.707/s -- -60% -75%
buk 1.75/s 147% -- -38%
jfn 2.80/s 296% 60% --
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.