APM: regularni vyrazy
Jenda Krynicky
Jenda at Krynicky.cz
Tue Jul 9 09:05:02 CDT 2002
Zkousel jsem si benchmarknout jestli Perl je dostatecne intelignetni
aby dokazal optimalizovat regularni vyrazy jak jsme se o tom vcera
bavili. Neni. Ale mezi [cdefgh] a (?:c|d|e|f|g|h) uz moc rozdil neni.
use Benchmark;
my @s = ("aaaa" .. "bbbb");
sub Group {
my $res = 0;
for (@s) {
/ab[cdefgh]/ and $res++;
}
return $res;
}
sub ORs {
my $res = 0;
for (@s) {
/abc|abd|abe|abf|abg|abh/ and $res++;
}
return $res;
}
sub SmallORs {
my $res = 0;
for (@s) {
/ab(?:c|d|e|f|g|h)/ and $res++;
}
return $res;
}
timethese 500, {
Group => \&Group,
ORs => \&ORs,
SmallORs => \&SmallORs,
}
Perl v5.6.1 built for MSWin32-x86-multi-thread
Benchmark: timing 500 iterations of Group, ORs, SmallORs...
Group: 9 wallclock secs ( 9.05 usr + 0.00 sys = 9.05 CPU)
@ 55.23/s (n=500)
ORs: 30 wallclock secs (27.72 usr + 0.01 sys = 27.73 CPU)
@ 18.03/s (n=500)
SmallORs: 10 wallclock secs ( 9.18 usr + 0.01 sys = 9.19 CPU)
@ 54.39/s (n=500)
Perl 5.8 RC2 ( v5.7.3 built for MSWin32-x86-multi-thread) dava
prakticky stejne vysledky:
Benchmark: timing 500 iterations of Group, ORs, SmallORs...
Group: 12 wallclock secs (11.55 usr + 0.01 sys = 11.56 CPU)
@ 43.26/s (n=500)
ORs: 33 wallclock secs (31.02 usr + 0.04 sys = 31.06 CPU)
@ 16.10/s (n=500)
SmallORs: 13 wallclock secs (11.62 usr + 0.01 sys = 11.63 CPU)
@ 43.00/s (n=500)
Jenda
=========== Jenda at Krynicky.cz == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
--- me
---------------------------------------------------------------------
To unsubscribe send a mail to majordomo at hfb.pm.org
with command "unsubscribe prague-pm" in the message body.
More information about the Prague-pm
mailing list