in reply to Re: parsing question
in thread parsing question

Out of interest with the experimental ?>, I did a benchmark with the following little test:
use Benchmark; $str1 = "_test (folloed by 1 or more spaces)"; $str2 = "_test < xxx >"; timethese ( 1000000, { 'p1' => '&p1;', 'p2' => '&p2;', 'p3' => '&p3;', 'p4' => '&p4;', } ); sub p1 () { $str1 =~ /_test(?>\s+)(?!<)/; } sub p2 () { $str1 =~ /_test(?:\s+)(?!<)/; } sub p3 () { $str2 =~ /_test(?>\s+)(?!<)/; } sub p4 () { $str2 =~ /_test(?:\s+)(?!<)/; }
I got the following results:
Benchmark: timing 1000000 iterations of p1, p2, p3, p4... p1: 3 wallclock secs ( 3.00 usr + 0.00 sys = 3.00 CPU) @ 333333.33/s (n=1000000) p2: 3 wallclock secs ( 2.79 usr + 0.00 sys = 2.79 CPU) @ 358422.94/s (n=1000000) p3: 3 wallclock secs ( 3.09 usr + 0.00 sys = 3.09 CPU) @ 323624.60/s (n=1000000) p4: 3 wallclock secs ( 2.82 usr + 0.00 sys = 2.82 CPU) @ 354609.93/s (n=1000000)
It seems that the ?> runs slower than ?: matching by as much as 10 percent. So am I correct to say that optimization wise, the ?> might not be the first choice?

Replies are listed 'Best First'.
Re: Re: Re: parsing question
by Anonymous Monk on Sep 15, 2003 at 03:06 UTC
    Switching timethese with cmpthese , here's the math
    Win32  ActivePerl 5.6.1 (Build 633)
           Rate  p4  p3  p1  p2
    p4 865052/s  -- -1% -1% -4%
    p3 876424/s  1%  -- -0% -3%
    p1 877193/s  1%  0%  -- -3%
    p2 901713/s  4%  3%  3%  --
    
    Win32  ActivePerl 5.8.0 (build 804)
    
           Rate  p3  p1  p2  p4
    p3 831255/s  -- -3% -5% -8%
    p1 853971/s  3%  -- -3% -5%
    p2 876424/s  5%  3%  -- -3%
    p4 900901/s  8%  5%  3%  --
    
    p1 and p3 use the "cut" operator. The optimization depends on your perl version.