in reply to Re^2: Simple regular expression problem
in thread Simple regular expression problem

Benchmarking is fun. However you should consider your results a little more carefully before making recomendation on them. This would definitly count as a minor optimization at best since we are talking about 32k instead of 40k per second. Which means unless you are are doing 100k's of these compares you are never going to notice the difference. Also interesting is the result of that benchmark on my machine:

1..2 Rate plain sticky plain 23682/s -- -1% sticky 23904/s 1% -- ok 1 ok 2

Oddly the difference dropped to mere 100s per second.


___________
Eric Hodges

Replies are listed 'Best First'.
Re^4: Simple regular expression problem
by Perl Mouse (Chaplain) on Oct 03, 2005 at 15:30 UTC
    Well, that would be 192K vs. 240K, as the test does 6 regexes per iteration. However, if we would test against the string:
    ('a3' x 100) . '!3'
    the difference would be:
    Rate sticky plain sticky 13273/s -- -95% plain 270490/s 1938% --
    Don't dismiss benchmarks too early as "an insignificant difference".
    Perl --((8:>*

      While that looks impressive and is certianly intersting, you missed my point. Even with that huge difference you are still talking about fractions of a second unless you are dealing with several 1k records at least. If you are only doing 100 matches, or even 1,000 matches you arn't going to see the difference. Are there certain things to optimize for when you are using large strings and large datasets? Of course. Are those optimizations things that you should always keep in mind? I don't think so. In this case I beleive that a clear meaning is better, now either solution might be clearer depending on the situation and the programmer. However my point was that your benchmark shouldn't cause anyone to avoid '?' in general just because of performance. There are certainly cases where you are right (for instance 10k strings that are 200+ characters long.), but I think for most general cases the performance differnce is minor and insignificant.


      ___________
      Eric Hodges