История изменений
Исправление DRVTiny, (текущая версия) :
Результат:
Preparing sampling matrix 100000x1000...
done
Benchmarking...
Benchmark: timing 100000 iterations of List::Util, Native::For, Native::Grep...
List::Util: 0 wallclock secs ( 0.25 usr + 0.00 sys = 0.25 CPU) @ 400000.00/s (n=100000)
(warning: too few iterations for a reliable count)
Native::For: 0 wallclock secs ( 0.12 usr + 0.00 sys = 0.12 CPU) @ 833333.33/s (n=100000)
(warning: too few iterations for a reliable count)
Native::Grep: 0 wallclock secs ( 0.31 usr + 0.00 sys = 0.31 CPU) @ 322580.65/s (n=100000)
(warning: too few iterations for a reliable count)
Для бенчмарка вот такого:
#!/usr/bin/perl
use 5.16.1;
use constant {
DFLT_ITER_COUNT => 1000,
DFLT_VEC_LENGTH => 100,
};
use strict;
use Time::HiRes;
use Benchmark qw(:all);
use List::Util qw(first);
use List::Util::XS 1.20;
use Getopt::Std;
getopts('i:l:', \my %opt);
my ($iterCount, $vecLength) = ($opt{'i'} || DFLT_ITER_COUNT, $opt{'l'} || DFLT_VEC_LENGTH);
say "Preparing sampling matrix ${iterCount}x${vecLength}...";
my @rndNums=map { [map { int(rand($vecLength)) } 1..$vecLength] } 1..$iterCount;
say 'done';
say 'Benchmarking...';
timethese($iterCount, {
'List::Util' => sub {
my $r=first { ($_&3) == 0 } @{$rndNums[int(rand($iterCount))]}
},
'Native::For' => sub {
my $r;
!($_&3) and $r=$_, last for @{$rndNums[int(rand($iterCount))]};
$r
},
'Native::Grep' => sub {
my $r;
LABEL: { grep { !($_&3) and $r=$_, last(LABEL) } @{$rndNums[int(rand($iterCount))]} }
$r
},
});
Исходная версия DRVTiny, :
Результат:
Preparing sampling matrix 100000x1000...
done
Benchmarking...
Benchmark: timing 100000 iterations of List::Util, Native::For, Native::Grep...
List::Util: 3 wallclock secs ( 3.08 usr + 0.00 sys = 3.08 CPU) @ 32467.53/s (n=100000)
Native::For: 0 wallclock secs ( 0.13 usr + 0.00 sys = 0.13 CPU) @ 769230.77/s (n=100000)
(warning: too few iterations for a reliable count)
Native::Grep: 0 wallclock secs ( 0.31 usr + 0.00 sys = 0.31 CPU) @ 322580.65/s (n=100000)
(warning: too few iterations for a reliable count)
Для бенчмарка вот такого:
#!/usr/bin/perl
use 5.16.1;
use constant {
DFLT_ITER_COUNT => 1000,
DFLT_VEC_LENGTH => 100,
};
use strict;
use Time::HiRes;
use Benchmark qw(:all);
use List::Util qw(first);
use List::Util::XS 1.20;
use Getopt::Std;
getopts('i:l:', \my %opt);
my ($iterCount, $vecLength) = ($opt{'i'} || DFLT_ITER_COUNT, $opt{'l'} || DFLT_VEC_LENGTH);
say "Preparing sampling matrix ${iterCount}x${vecLength}...";
my @rndNums=map { [map { int(rand($vecLength)) } 1..$vecLength] } 1..$iterCount;
say 'done';
say 'Benchmarking...';
timethese($iterCount, {
'List::Util' => sub {
my $r=first { ! $_&3 } @{$rndNums[int(rand($iterCount))]}
},
'Native::For' => sub {
my $r;
!($_&3) and $r=$_, last for @{$rndNums[int(rand($iterCount))]};
$r
},
'Native::Grep' => sub {
my $r;
LABEL: { grep { !($_&3) and $r=$_, last(LABEL) } @{$rndNums[int(rand($iterCount))]} }
$r
},
});