Hello All,
I am a bit confused with the below benchmarks. I have read in multiple places, including a regex tutorial here, to avoid the /g modifier when it is not needed. This made sense to me in that it shouldn't have to continue searching once it has found a match, if the first match is what you're looking for.
The below metrics (in the code comments) don't seem to bare this out. Can anyone alleviate my confusion?
use Time::HiRes qw(sleep time); my $time = time; for (1..1_000_000) { my $str = '123456789'; my ($a,$b) = $str =~ m/(23)[^8]+(8)/g; # about 1.88 sec #my ($a,$b) = $str =~ m/(23)[^8]+(8)/; # about 2.15 sec #my ($a) = $str =~ m/(23)/g; # about 1.23 sec #my ($a) = $str =~ m/(23)/; # about 1.41 sec } say time - $time;
Edit: I'm running Strawberry 5.12.3
In reply to Why does global match run faster than none global? by Kc12349
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |