in reply to Re^2: Performance optimization question
in thread Performance optimization question

General request|comment: Could we have a failing test too in benchmarks (at least for regex, index, and such)?
  • Comment on Re^3: Performance optimization question

Replies are listed 'Best First'.
Re^4: Performance optimization question
by moritz (Cardinal) on Apr 03, 2008 at 08:18 UTC
    Sure. Go ahead, provide one.

    In general this is a really good idea, especially for regexes that might do some backtracking. In this case it won't happen, so it's not very exiting:

    # perl 5.10.0 # match: Rate REGEX INDEX REGEX 87061/s -- -1% INDEX 87682/s 1% -- # fail: Rate REGEX INDEX REGEX 43840/s -- -1% INDEX 44246/s 1% --

    Since the found text is in the middle it takes twice as long when there is no match.

      After all examples given by all of you I decided that the best way for me to improve my performance is
      1) to use regex for forming array
      2) regex should be as simple as possible which can be done by adjusting it to my particular case

      So could you confirm that it will always work correctly:
      my string is always like
      143,2|3674,9|12,5|......|145,9
      so in |X,Y| Y is always single digit
      and I want to have an array of pairs
      @arr = (X1,Y1)(X2,Y2)... Then the simplest way is:
      $r = 9; # or any single number my @arr = $string =~ /([^,|]+\,$r)/g;
      It actually works but am I right?