in reply to Are perlfaq6 and perlop correct about "/o" modifier?

First, I removed the incorrect /c which totally breaks the benchmark.

Then I added a qr-using solution since one might argue that it's qr that "obsoletes /o".

use strict; use warnings; use feature 'say'; use Benchmark 'cmpthese'; my $pat = qr/\d+/; my $s = '123abc' x 1e6; my $re = qr/\G $pat \D+ /x; cmpthese -1, { "o=0" => sub { 1 while $s =~ /\G $pat \D+ /gx }, "qr" => sub { 1 while $s =~ /$re/g }, "o=1" => sub { 1 while $s =~ /\G $pat \D+ /gxo }, };
Rate o=0 qr o=1 o=0 3.12/s -- -8% -59% qr 3.39/s 8% -- -55% o=1 7.55/s 142% 123% --

...and we still get a large divide. Your point remains, but it now has a valid foundation.

Note that /o is only 140% faster and not 750% faster. That's probably because of your /c bug.

Replies are listed 'Best First'.
Re^2: Are perlfaq6 and perlop correct about "/o" modifier?
by Anonymous Monk on May 09, 2026 at 17:46 UTC
    Note that /o is only 140% faster and not 750% faster.

    I ran this under a few versions of Perl and /o is 200% faster with 5.42.0 because qr and o=0 are slower!

    5.42.0:

          Rate  o=0   qr  o=1
    o=0 4.17/s   -- -14% -67%
    qr  4.85/s  17%   -- -61%
    o=1 12.5/s 200% 158%   --
    
    5.38.2:
          Rate  o=0   qr  o=1
    o=0 5.22/s   -- -17% -58%
    qr  6.31/s  21%   -- -50%
    o=1 12.5/s 140%  98%   --
    
    5.16.3:
          Rate  o=0   qr  o=1
    o=0 8.26/s   --  -4% -38%
    qr  8.57/s   4%   -- -36%
    o=1 13.4/s  62%  56%   --