Benchmark モジュールの使い方
いつも陰ながらお世話になっているid:fbisさんところで、各種コンスタントのBenchmarkテストがありました。
Benchmarkは使ったことがないと思ったのですが、ググルとなんと9年前の2000年の掲示板に自分の書き込みあり、benchmarkを使っているのです。
しかし、すっかり忘れている自分・・・ってPerlは5年以上ブランクがあるので・・・。
で、引きつづきググルと良いページを2つ見つけました!
- http://iandeth.dyndns.org/mt/ian/archives/000588.html
- http://text.art-code.org/presen/yokohama.pm/2/
最後にPerldoc Benchmarkで使い方のところを引用しときます。
NAME
Benchmark - benchmark running times of Perl code
SYNOPSIS
use Benchmark qw(:all) ;
timethis ($count, "code");
# Use Perl code in strings...
timethese($count, {
'Name1' => '...code1...',
'Name2' => '...code2...',
});
# ... or use subroutine references.
timethese($count, {
'Name1' => sub { ...code1... },
'Name2' => sub { ...code2... },
});
# cmpthese can be used both ways as well
cmpthese($count, {
'Name1' => '...code1...',
'Name2' => '...code2...',
});
cmpthese($count, {
'Name1' => sub { ...code1... },
'Name2' => sub { ...code2... },
});
# ...or in two stages
$results = timethese($count,
{
'Name1' => sub { ...code1... },
'Name2' => sub { ...code2... },
},
'none'
);
cmpthese( $results ) ;