2
1

More than 5 years have passed since last update.

ベンチマークをとる

Last updated at Posted at 2015-12-11

こんばんは :whale2:

Perl 6 Advent Calendar 2015の11日目です。(あとで書き直したい :cry: )

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%  | --     |
------------------------------------

参考と参照

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1