http://www.perlmonks.org?node_id=282591


in reply to Advanced Sorting - GRT - Guttman Rosler Transform

Generally speaking the GRT is a signifigant improvement on the ST

But it doesn't seem te be an improvement with your example sort:

Benchmark: running bare, grt, st for at least 3 CPU seconds... bare: 6 wallclock secs ( 3.08 usr + 0.01 sys = 3.09 CPU) @ 12 +79584.47/s (n=3953916) grt: 8 wallclock secs ( 3.11 usr + 0.00 sys = 3.11 CPU) @ 11 +18145.66/s (n=3477433) st: 7 wallclock secs ( 3.05 usr + 0.01 sys = 3.06 CPU) @ 11 +46781.05/s (n=3509150) Rate grt st bare grt 1118146/s -- -2% -13% st 1146781/s 3% -- -10% bare 1279584/s 14% 12% --

#!/usr/bin/perl -w use strict; use Benchmark qw(cmpthese); my @words = qw(The time has come the Walrus said to speak of many thin +gs); cmpthese(-3, { st => q{ my @sorted = map { $_->[1] } sort { $a->[0] <=> $a->[0] || $a->[1] cmp $b->[1] } map { [ tr/eE/eE/, $_ ] } @words; }, grt => q{ my @sorted = map { substr($_, 4) } sort map { pack("LA*", tr/eE/eE/, $_) } @words; }, bare => q{ my @sorted = sort { ($a =~ tr/eE/eE/) <=> ($b =~ tr/eE/eE/) } +@words; } });
This is perl, v5.8.0 built for i686-linux

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }