in reply to Re^8: Common Perl Pitfalls
in thread Common Perl Pitfalls
But when the regexes get large, and difference of compiling the patterns is a few seconds vs a few minutes, I do care.
But still, even in your simple example, it's three compilations + two stringifications vs a single compile.
Here's a benchmark, 1 compilation vs 12 compilations and 20 stringifications:
That's with 5.15.9 (on OSX). With 5.12.3 (same box), I get:use Benchmark 'cmpthese'; cmpthese -1, { qq => 'my $p = qq{a}; $p = qq{$p$p} for 1 .. 10; qr/$p/', qr => 'my $p = qr{a}; $p = qr{$p$p} for 1 .. 10; qr/$p/', }; __END__ Rate qr qq qr 914/s -- -100% qq 283880/s 30949% --
And, for kicks, with 5.8.9 (again, same box):Rate qr qq qr 857/s -- -100% qq 324588/s 37769% --
The resulting patterns, while identical, also differ significantly in size: the one build with repeated qr constructs is 19 times the size of the one build with qq.Rate qr qq qr 508/s -- -100% qq 301810/s 59290% --
I'm usually not a stickler for speed. But I make an exception when it comes to qr.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: Common Perl Pitfalls
by Jenda (Abbot) on Apr 11, 2012 at 22:48 UTC | |
by JavaFan (Canon) on Apr 11, 2012 at 23:36 UTC |