【えっ】Perlに未来はあるのか?【終わり?】
■ このスレッドは過去ログ倉庫に格納されています
0121デフォルトの名無しさん
2007/07/31(火) 04:11:27そのコードで何を計測しているつもりなんだ?
#!/usr/bin/perl -w
use strict;
use Benchmark qw(timethese);
my $i = 0;
my $str = join '', 'a'..'m';
my @line;
push(@line, $str), substr($str, 0, 0, chop $str) for 1..1000;
timethese(-5, {
re1 => sub { /^(?=(?:abcdef|ghijklm))/ and ++$i for @line },
re2 => sub { /^(?=abcdef)/ || /^(?=ghijklm)/ and ++$i for @line },
re3 => sub { /^abcdef/ || /^ghijklm/ and ++$i for @line },
idx => sub { index($_, 'abcdef', 0) == 0 || index($_, 'ghijklm', 0) == 0 and ++$i for @line },
});
@line = ();
push @line, join '', map +('a','b')[ rand 2 ], 1..10 for 1..1000;
timethese(-5, {
re1 => sub { /^(?=ab..)(?=..ab)/ and ++$i for @line },
re2 => sub { /^(?=ab..)/ && /^(?=..ab)/ and ++$i for @line },
re3 => sub { /^ab../ && /^..ab/ and ++$i for @line },
idx => sub { index($_, 'ab', 0) == 0 && index($_, 'ab', 2) == 2 and ++$i for @line },
});
■ このスレッドは過去ログ倉庫に格納されています