tiny-regex-c icon indicating copy to clipboard operation
tiny-regex-c copied to clipboard

simplify matchplus and matchstar

Open marler8997 opened this issue 4 years ago • 1 comments

matchplus can be simplified by only modifying matchlength once the complete match is successful. This means it doesn't have to rewind matchlength as it iterates through each possible matchpattern. This also means it keeps matchlength unmodified if it doesn't return a match. Because of this last part, this also means that matchstar can leverage matchplus which reduces it to single line of code return matchplus(...) || matchpattern(..).

marler8997 avatar Mar 07 '21 12:03 marler8997

Very interestingly, this change has noticeably improved performance. Before this change, running time ./tests/test2 3 times in a row gave these times:

real	0m4.047s
real	0m5.525s
real	0m3.952s

After this change I'm consistently getting below 3.6:

real	0m3.577s
real	0m3.571s
real	0m3.587s

The run times are much more consistent and it's around a 25% improvement for that test. My guess is that this performance may be due to less code needed to be swapped in and out of the icache? Not sure, but interesting.

marler8997 avatar Mar 07 '21 13:03 marler8997