Dear Monks i need your help again.
I have some code (not my) that use g and o matching modifiers. I think there is no need in them but this code show strange result. It ran faster than without this modifiers.
Can you explain why?
Here is code:
#!/usr/bin/perl -W use warnings; use strict; use Benchmark; my $phrase1 = 'network'; my $phrase2 = 'networK'; my ($t1, $t2); ########################################## $t1 = new Benchmark; for (1..10000000) { if ($phrase1 =~ /^network$/go) {} } $t2 = new Benchmark; print timestr (timediff ($t2, $t1)), "\n"; ########################################## $t1 = new Benchmark; for (1..10000000) { if ($phrase2 =~ /^networK$/) {} } $t2 = new Benchmark; print timestr (timediff ($t2, $t1)), "\n";
And here is result:
7 wallclock secs ( 6.40 usr + 0.01 sys = 6.41 CPU) 9 wallclock secs ( 9.06 usr + 0.00 sys = 9.06 CPU)
In reply to Why this code run faster? by Gangabass
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |