in reply to How useful is the /o regexp modifier?

/o can be rather confusing, so I try to avoid it.

Your benchmark basically shows that on perl-5.8.8, the qr, qr/o and /o variants have the same run time, and when I run it multiple times, it actually fluctuates enough to call the differences "noise".

On perl-5.10.0 the /o variant is consistently ~33% faster than qr/ and qr/o.

But remeber that your cases are pretty pathologic in that the regex is rather unusually long, and the string is shorter than the text representation of the regex. If you increase the length of your strings by a factor of 10, you're again in a regime where the run time differences are smaller than 5% (and this time all of them), so I'd conclude that for any practical purpose the possible small efficiency gain is neglectable.

Replies are listed 'Best First'.
Re^2: How useful is the /o regexp modifier?
by kyle (Abbot) on Feb 04, 2009 at 04:03 UTC

    your cases are pretty pathologic

    I think that's my problem. What I'd like is a regex that's hard to compile, but what I made instead are ones that are hard to match. Not knowing anything about the compilation process, I don't know how to design something that will take a long time to compile (and match quickly) so as to show the compilation step.

      How about these:

      m{.|<long pattern>} m{\!<long pattern>} # with ! not anywhere in the string you match

      Both will match any long pattern very fast, the first one should be the fastest match possible as it matches just the first char of the string to match.

      It could be that the long patterns are optimized away, that should be tested

      UPDATE: On second thought, whether they are optimized away doesn't really matter as long as the compilation takes more time, and it does, at least with perl 5.8.8

      #with short pattern m{.|U*e?Z+} horrid rx matches string Rate // qr/o qr /o // 1254/s -- -29% -30% -34% qr/o 1771/s 41% -- -1% -7% qr 1781/s 42% 1% -- -7% /o 1912/s 52% 8% 7% -- #with long pattern m{.|U*e?Z+J{0,1}z*4{0,1}7?d*H+k*l+N+d{0,1}4+9{0,1} +... 1000 more subpattern horrid rx matches string Rate // qr qr/o /o // 235/s -- -87% -87% -88% qr 1770/s 654% -- -1% -7% qr/o 1781/s 659% 1% -- -7% /o 1912/s 715% 8% 7% --