Subject: | regular expression performance oddities |
Devel::NYTProf (which I love, keep up the good work!) just sent me off
optimizing what turned out to be profiling overhead error :-/ -- I've
boiled down the behavior I was bitten by to a simple test case - it
appears that regular expressions perform very significantly slower with
Devel::NYTProf enabled. All versions were tested on a 64-bit ubuntu
10.04 (perl 5.10.1) install. 4.04 was also tested on a 64-bit debian
etch (perl 5.8.8) install.
ski@portege:~$ time perl -le 'my @x = (0..100_000); @x = grep { rand() <
1/2 } @x'
real 0m0.076s
user 0m0.050s
sys 0m0.030s
ski@portege:~$ time perl -d:NYTProf -le 'my @x = (0..100_000); @x = grep
{ rand() < 1/2 } @x'
real 0m0.108s
user 0m0.070s
sys 0m0.020s
ski@portege:~$
ski@portege:~$ time perl -le 'my @x = (0..100_000); @x = grep { /234/ } @x'
real 0m0.197s
user 0m0.110s
sys 0m0.040s
ski@portege:~$ time NYTPROF=slowops=2 perl -d:NYTProf -le 'my @x =
(0..100_000); @x = grep { /234/ } @x' #default
real 0m1.744s
user 0m1.530s
sys 0m0.040s
ski@portege:~$ time NYTPROF=slowops=0 perl -d:NYTProf -le 'my @x =
(0..100_000); @x = grep { /234/ } @x' #default
real 0m0.801s
user 0m0.720s
sys 0m0.020s
Why is the slowdown large? I noticed that even using qr//, regular
expressions seem to get re-CORE::regcomp'd every run (although this may
be intended behavior, it's certainly counter-intuitive) - perhaps there
is a regular expression in the hooked-in code that deletes the
optimizations that perl does for when the last regular expression is
repeated?
Any ideas?
Thanks again!
Brian Szymanski