Gangabass has asked for the wisdom of the Perl Monks concerning the following question:
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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why this code run faster?
by shmem (Chancellor) on Nov 08, 2007 at 17:57 UTC | |
|
Re: Why this code run faster?
by kyle (Abbot) on Nov 08, 2007 at 17:19 UTC | |
by ikegami (Patriarch) on Nov 08, 2007 at 17:27 UTC | |
by gamache (Friar) on Nov 08, 2007 at 17:31 UTC | |
by Gangabass (Vicar) on Nov 09, 2007 at 01:33 UTC | |
by gamache (Friar) on Nov 08, 2007 at 17:27 UTC | |
|
Re: Why this code run faster?
by gamache (Friar) on Nov 08, 2007 at 16:42 UTC | |
by chromatic (Archbishop) on Nov 08, 2007 at 17:14 UTC | |
by diotalevi (Canon) on Nov 08, 2007 at 17:34 UTC | |
by jasonk (Parson) on Nov 08, 2007 at 17:17 UTC |