Rate ikegami_sort ikegami op op_nosort
ikegami_sort 4.68/s -- -1% -75%% -91%
ikegami 4.72/s 1% -- -75%% -91%
op 19.1/s 308% 304% --% -62%
op_nosort 50.6/s 981% 970% 165% --
####
Rate ikegami_sort ikegami op op_nosort
ikegami_sort 0.345/s -- -1% -68% -88%
ikegami 0.348/s 1% -- -68% -88%
op 1.08/s 214% 212% -- -63%
op_nosort 2.90/s 738% 733% 167% --
##
##
use Benchmark qw/cmpthese timethese :hireswallclock/;
my $N = 1e6; # N
my @allrefs = map { 1e5 + int rand 9e5 } 1..$N;
my %uni_refs = map { 1e6 + int rand 9e6 => $_ } 1..$N;
cmpthese(timethese(-10, {
op => \&op,
op_nosort => \&op_nosort,
ikegami => \&ikegami,
ikegami_sort => \&ikegami,
}));
sub op {
my @refs = @allrefs[ sort { $a <=> $b } values %uni_refs ]
}
sub op_nosort {
my @refs = @allrefs[ values %uni_refs ]
}
sub ikegami {
my %keep = map { $_ => 1 } values %uni_refs;
my @refs = @allrefs[ grep $keep{$_}, 0..$#allrefs ];
}
sub ikegami_sort {
my %keep = map { $_ => 1 } values %uni_refs;
my @refs = @allrefs[ sort { $a <=> $b } grep $keep{$_}, 0..$#allrefs ];
}