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: parsing question
by Abigail-II (Bishop) on Sep 15, 2003 at 07:01 UTC
    Considering that /_test(?:\s+)(?!<)/ is wrong, as demonstrated elsewhere in this thread, I fail to see your point.

    Abigail

      Hi Ab, but I have tested the following code, which were giving me the same test results on many test cases:
      if ($str =~ /_test(?>\s+)(?!<)/) { print "test ok\n" } if ($str =~ /_test(?:\s+)(?!<)/) { print "test ok\n" }
      Could you please tell me as why the /_test(?:\s+)(?!<)/ is wrong? I want to learn. Thanks!
        As I said before, it was pointed out elsewhere in this thread. In one of my postings, I showed a program pointing out the differences. Please read the entire thread - it's not that there are 500 postings.

        Abigail