こんばんは
Perl 6 Advent Calendar 2015の11日目です。(あとで書き直したい )
Perl6の処理のベンチマークを取るにはBench
モジュールを使います。
.timethis
1つの処理。
use v6;
use Bench;
my $繰り返し回数 = 1 #`(回) ;
my $bench = Bench.new;
$bench.timethis(
$繰り返し回数,
sub{ sleep 0.05; },
title => 'hoge',
);
結果
hoge: 0.0505 wallclock secs @ 19.8048/s (n=1)
(warning: too few iterations for a reliable count)
.timethese
2つ(以上)の処理。
use v6;
use Bench;
my $繰り返し回数 = 1 #`(回) ;
my $bench = Bench.new;
$bench.timethese(
$繰り返し回数,
{
first => sub { sleep .05; },
second => sub { sleep .005; },
}
);
結果
Benchmark:
Timing 1 iterations of first, second...
first: 0.0553 wallclock secs @ 18.0730/s (n=1)
(warning: too few iterations for a reliable count)
second: 0.0063 wallclock secs @ 157.8728/s (n=1)
(warning: too few iterations for a reliable count)
.cmpthese
2つ(以上)の処理を比較して表を出力してくれます。
use v6;
use Bench;
my $繰り返し回数 = 1 #`(回) ;
my $bench = Bench.new;
$bench.cmpthese(
$繰り返し回数,
{
:first( sub { sleep .05; } ),
:second( sub { sleep .005; } ),
});
結果
Benchmark:
Timing 1 iterations of first, second...
first: 0.0525 wallclock secs @ 19.0299/s (n=1)
(warning: too few iterations for a reliable count)
second: 0.0060 wallclock secs @ 167.6427/s (n=1)
(warning: too few iterations for a reliable count)
O--------O--------O-------O--------O
| | Rate | first | second |
O========O========O=======O========O
| first | 19.0/s | -- | -89% |
| second | 168/s | 781% | -- |
------------------------------------