qq(),q(),qx()
2003-10-16-4: [Perl]
qq(hoge): "hoge"
q(hoge) : 'hoge'
qx(hoge): `hoge`
Benchmark パッケージの timethese でベンチマークが取れる.
#!/usr/env/bin perl
use Benchmark;
$count = 1000;
timethese($count, {
'$a = $a . "a"' => sub {
for ($i = 0; $i < 100; $i++) {
$a = $a . "a"
}
},
'$a .= "a" ' => sub {
for ($i = 0; $i < 100; $i++) {
$a .= "a"
}
},
});
出力
Benchmark: timing 10000 iterations of $a .= "a" , $a = $a . "a"...
$a .= "a" : 0 wallclock secs ( 0.17 usr + 0.00 sys = 0.17 CPU) @ 5882.35/s (n=1000)
$a = $a . "a": 85 wallclock secs (84.41 usr + 0.01 sys = 84.42 CPU) @ 11.85/s (n=1000)
・・・$a = $a . "a" はめたくそに遅い.
回数が少なすぎると
(warning: too few iterations for a reliable count)
と warning が出る
2003-10-16-2: [Code]
(ISBN を引数として渡す)
sub amazon {
my ($k) = @_;
my $o = $k;
$k =~ s/[^0-9a-zA-Z]//g;
return qq(<a href="http://www.amazon.co.jp/o/ASIN/$k/">$o</a>);
}