速い足し算。
今日は会社休んだから、素直にいつものお医者さんに行った。
そしたら、お医者さんも風邪ひいてた。
風邪、めっさ流行ってるよねぇ…。みなさんお大事に。
さて、寝てばっかいても退屈なので<おい
仕事がらみの情報収集とかテストとかやりつつ
以前から、ちょっと気になってた
perl の足し算について、計測してみる。
#!/usr/bin/perl -wuse strict;
use Benchmark qw(:all);
my $testA = 0;
my $testB = 0;
my $testC = 0;
my $result = timethese(1000000, {
testa => sub { $testA++; },
testb => sub { $testB += 1; },
testc => sub { $testC = $testC + 1; }
});
cmpthese($result);
exit;
私にしては珍しく、理屈っぽくない変数名達です(笑)
何故なら、風邪で弱ってて、変数名考える気力がないから。
で、結果。
Benchmark: timing 1000000 iterations of testa, testb, testc...testa: 0 wallclock secs ( 0.11 usr + 0.00 sys = 0.11 CPU) @ 9259259.26/s (n=1000000)
(warning: too few iterations for a reliable count)
testb: 0 wallclock secs ( 0.17 usr + 0.00 sys = 0.17 CPU) @ 5813953.49/s (n=1000000)
(warning: too few iterations for a reliable count)
testc: 0 wallclock secs ( 0.11 usr + 0.00 sys = 0.11 CPU) @ 9174311.93/s (n=1000000)
(warning: too few iterations for a reliable count)
Rate testb testc testa
testb 5813953/s -- -37% -37%
testc 9174312/s 58% -- -1%
testa 9259259/s 59% 1% --
ほほぅ。個人的には見た目の美しいと思ってる testA に勝って(?)欲しかったですなぁ…。
悲しいけど testB パターンで足し算するようにしますか…。
…って、いや、testAが勝ってるやんね…orz
訂正しまーす。testAパターンを使い続けまーす♪