R.A. Epigonos et al.

[perl] use Benchmarkでベンチマークする際の雛形

ユニットテストで速度比較したい場合、同じ処理を行うサブルーチンの速度比較したい場合はuse Benchmarkする。この場合の雛形。

雛形は以下。

$ cat bench.pl
#!/usr/bin/perl -w
use strict;
use warnings;
use Benchmark qw/cmpthese timethese/;

my $count = 10000;
my $obj2 = Hoge->new("hoge");
my $obj1 = Fuga->new("hoge");

cmpthese(
                timethese($count,
                        {'TEST1' => '&test1;', 'TEST2' => '&test2;', })
        );

exit;

sub test1 {
        $obj1->fuga;
}

sub test2 {
        $obj2->hoge;
}
__END__

timetheseで経過時間、cmptheseをで速度比較結果を出力してくれる。

$ perl bench.pl
Benchmark: timing 10000 iterations of TEST1, TEST2...
     TEST1:  0 wallclock secs ( 0.66 usr +  0.00 sys =  0.66 CPU) @ 15151.52/s (n=10000)
     TEST2: 33 wallclock secs (31.83 usr +  0.03 sys = 31.86 CPU) @ 313.87/s (n=10000)
         Rate TEST2 TEST1
TEST2   314/s    --  -98%
TEST1 15152/s 4727%    --

リファレンス

  1. 404 Blog Not Found:perl tips - Encodeを速く使う方法
  2. dan kogai use benchmark - Google 検索
  3. Perlのベンチマーク(use Benchmark;)/楽
  4. use Benchmark ベンチマークに際しての留意点 - hibomaのはてなダイアリー
  5. perl use benchmark - Google 検索
  6. Benchmark - perldoc.perl.org
  7. perl use benchmark - Google 検索
  8. Benchmark - Perl コードの実行時間のベンチマークを行なう
  9. ここギコ!: PerlのBenchmarkで出るベンチマーク値は、いったい何を表すのだろう?
  10. いまさら聞けないPerlのお役立ちワザ(3) - いまさら聞けないPerlのお役立ちワザ:ITpro

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2009-07-31T16:29:24+09:00
  2. Modified: 2009-07-31T16:29:24+09:00
  3. Generated: 2023-08-27T23:09:12+09:00