frei

旧「anney's room」からブログ「frei」だけ引っ越し&残しました

\d。

基本的な事なのに「\d」が数字を示す事を、すぐに忘れる。

何故なら、普段 私は [0-9] を好んで使うからなのだけど。

そういやぁ、どっちが速いんだ?

#!/usr/bin/perl -w

use strict;

use Benchmark qw(:all);

my $testString = '000,111,222,333,444,555,666,777';

my $result = timethese(1000000, {

testA => sub {

my (@tmpArray) = $testString =~ /(?:(\d+),?)/g;

},

testB => sub {

my (@tmpArray) = $testString =~ /(?:([0-9]+),?)/g;

}

});

cmpthese($result);

exit;

Benchmark: timing 1000000 iterations of testA, testB...

testA: 13 wallclock secs (10.83 usr + 2.23 sys = 13.06 CPU) @ 76569.68/s (n=1000000)

testB: 13 wallclock secs ( 7.83 usr + 5.60 sys = 13.43 CPU) @ 74460.16/s (n=1000000)

Rate testB testA

testB 74460/s -- -3%

testA 76570/s 3% --

Benchmark: timing 1000000 iterations of testA, testB...

testA: 15 wallclock secs (11.34 usr + 3.78 sys = 15.12 CPU) @ 66137.57/s (n=1000000)

testB: 14 wallclock secs (10.44 usr + 3.76 sys = 14.20 CPU) @ 70422.54/s (n=1000000)

Rate testA testB

testA 66138/s -- -6%

testB 70423/s 6% --

うーん、たいした差じゃないので、気にするな、って所かな。

個人的には、やっぱり [0-9] がいいな。