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 |