How to track regular expression matching performance?

Is there a convenient way to get a trace of the state of a regular expression engine when evaluating an expression m//or s///?


By the way, I know that there is a Regexp :: Debugger package available through CPAN (and this is amazingly cool), but I see no way to get something like a trace from it; I do not want to go through a huge number of steps.

+4
source share
1 answer

Yes. Turn the regex engine into debug mode and it will print what it does:

use re 'debug'; 

my $str = "abcdefg";
$str =~ m/[ef]+/;

Which gives the result:

Compiling REx "[ef]+"
Final program:
   1: PLUS (13)
   2:   ANYOF[ef] (0)
  13: END (0)
stclass ANYOF[ef] plus minlen 1 
Matching REx "[ef]+" against "abcdefg"
Matching stclass ANYOF[ef] against "abcdefg" (7 bytes)
   4 <abcd> <efg>            |  1:PLUS(13)
                                  ANYOF[ef] can match 2 times out of 2147483647...
   6 <abcdef> <g>            | 13:  END(0)
Match successful!
Freeing REx: "[ef]+"
+8
source

Source: https://habr.com/ru/post/1684307/


All Articles