Regex Engine Matching Speed Benchmark

This page contains benchmark results for various regex engines executing various different regexes on variuous different input data. For total 31 cases are shown here.

This page is maintained by Yichun Zhang (agentzh) <agentzh@gmail.com>.

Many test cases used here are taken directly from the performance test suite maintained by the author of PCRE JIT, Zoltan Herczeg.

Here we only consider regex engines and their APIs that do support full sub-match capturing.

You can find the original programs and data below if you want to check the details and/or run the benchmark yourself.

    https://github.com/openresty/sregex/tree/dfa/bench/

Just run the make && ./plot-all.pl command in that directory locally and then open the resulting ./index.html in your favoriate web browser.

The results were automatically generated at Sun Jul 26 14:45:58 2015.

Operating Systemon
GNU/Linux x86_64
CPU
Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
C Compiler
cc (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4)
PCRE
8.38-RC1 svn revision 1577
PCRE2
10.21-RC1 svn revision 319
RE2
git commit e68b52819a
SRegex DFA Prototype
git commit ee5944f108

Case 1

$ ./bench 'd' abc.txt
PCRE interp no match: 7.55729 ms elapsed (0 matches found, 5 repeated times).
PCRE JIT no match: 10.09936 ms elapsed (0 matches found, 5 repeated times).
PCRE2 interp no match: 1.44395 ms elapsed (0 matches found, 5 repeated times).
PCRE2 JIT no match: 10.49584 ms elapsed (0 matches found, 5 repeated times).
RE2 PartialMatch no match: 1.44119 ms elapsed (0 matches found, 5 repeated times).
SRegex DFA proto no match: 1.42354 ms elapsed (0 matches found, 5 repeated times).

Case 2

$ ./bench 'd|de' rand-abc.txt
PCRE interp no match: 3.23894 ms elapsed (0 matches found, 5 repeated times).
PCRE JIT no match: 4.17001 ms elapsed (0 matches found, 5 repeated times).
PCRE2 interp no match: 0.47217 ms elapsed (0 matches found, 5 repeated times).
PCRE2 JIT no match: 4.05083 ms elapsed (0 matches found, 5 repeated times).
RE2 PartialMatch no match: 0.48749 ms elapsed (0 matches found, 5 repeated times).
SRegex DFA proto no match: 0.45100 ms elapsed (0 matches found, 5 repeated times).

Case 3

$ ./bench 'dfa|efa|ufa|zfa' abc.txt
PCRE interp no match: 18.12142 ms elapsed (0 matches found, 5 repeated times).
PCRE JIT no match: 23.99425 ms elapsed (0 matches found, 5 repeated times).
PCRE2 interp no match: 18.00649 ms elapsed (0 matches found, 5 repeated times).
PCRE2 JIT no match: 23.64037 ms elapsed (0 matches found, 5 repeated times).
RE2 PartialMatch no match: 68.79878 ms elapsed (0 matches found, 5 repeated times).
SRegex DFA proto no match: 20.00296 ms elapsed (0 matches found, 5 repeated times).

Case 4

$ ./bench 'dfa|efa|ufa|zfa' mtent12.txt
PCRE interp no match: 141.78930 ms elapsed (419 matches found, 5 repeated times).
PCRE JIT no match: 51.44509 ms elapsed (419 matches found, 5 repeated times).
PCRE2 interp no match: 190.36975 ms elapsed (419 matches found, 5 repeated times).
PCRE2 JIT no match: 52.36987 ms elapsed (419 matches found, 5 repeated times).
RE2 PartialMatch no match: 74.36487 ms elapsed (419 matches found, 5 repeated times).
SRegex DFA proto no match: 45.79104 ms elapsed (419 matches found, 5 repeated times).

Case 5

$ ./bench '[d-z]' abc.txt
PCRE interp no match: 18.27690 ms elapsed (0 matches found, 5 repeated times).
PCRE JIT no match: 10.26124 ms elapsed (0 matches found, 5 repeated times).
PCRE2 interp no match: 18.73606 ms elapsed (0 matches found, 5 repeated times).
PCRE2 JIT no match: 10.12851 ms elapsed (0 matches found, 5 repeated times).
RE2 PartialMatch no match: 69.90074 ms elapsed (0 matches found, 5 repeated times).
SRegex DFA proto no match: 10.40516 ms elapsed (0 matches found, 5 repeated times).

Case 6

$ ./bench '[d-hx-z]' abc.txt
PCRE interp no match: 19.24882 ms elapsed (0 matches found, 5 repeated times).
PCRE JIT no match: 15.39392 ms elapsed (0 matches found, 5 repeated times).
PCRE2 interp no match: 18.22315 ms elapsed (0 matches found, 5 repeated times).
PCRE2 JIT no match: 13.43908 ms elapsed (0 matches found, 5 repeated times).
RE2 PartialMatch no match: 68.93757 ms elapsed (0 matches found, 5 repeated times).
SRegex DFA proto no match: 18.24794 ms elapsed (0 matches found, 5 repeated times).

Case 7

$ ./bench '[d-hx-z]' mtent12.txt
PCRE interp no match: 257.08519 ms elapsed (4209328 matches found, 5 repeated times).
PCRE JIT no match: 132.21802 ms elapsed (4209328 matches found, 5 repeated times).
PCRE2 interp no match: 228.28650 ms elapsed (4209328 matches found, 5 repeated times).
PCRE2 JIT no match: 94.71404 ms elapsed (4209328 matches found, 5 repeated times).
RE2 PartialMatch no match: 1004.47672 ms elapsed (4209328 matches found, 5 repeated times).
SRegex DFA proto no match: 59.57904 ms elapsed (4209328 matches found, 5 repeated times).

Case 8

$ ./bench 'ddd|fff|eee|ggg|hhh|iii|jjj|kkk|[l-n]mm|ooo|ppp|qqq|rrr|sss|ttt|uuu|vvv|www|[x-z]yy' mtent12.txt
PCRE interp no match: 2063.26743 ms elapsed (43 matches found, 5 repeated times).
PCRE JIT no match: 205.50080 ms elapsed (43 matches found, 5 repeated times).
PCRE2 interp no match: 3031.93439 ms elapsed (43 matches found, 5 repeated times).
PCRE2 JIT no match: 207.03297 ms elapsed (43 matches found, 5 repeated times).
RE2 PartialMatch no match: 104.88285 ms elapsed (43 matches found, 5 repeated times).
SRegex DFA proto no match: 111.39646 ms elapsed (43 matches found, 5 repeated times).

Case 9

$ ./bench 'ddd|fff|eee|ggg|hhh|iii|jjj|kkk|[l-n]mm|ooo|ppp|qqq|rrr|sss|ttt|uuu|vvv|www|[x-z]yy' abc.txt
PCRE interp no match: 18.41144 ms elapsed (0 matches found, 5 repeated times).
PCRE JIT no match: 10.12330 ms elapsed (0 matches found, 5 repeated times).
PCRE2 interp no match: 19.41505 ms elapsed (0 matches found, 5 repeated times).
PCRE2 JIT no match: 10.22509 ms elapsed (0 matches found, 5 repeated times).
RE2 PartialMatch no match: 68.63633 ms elapsed (0 matches found, 5 repeated times).
SRegex DFA proto no match: 10.42275 ms elapsed (0 matches found, 5 repeated times).

Case 10

$ ./bench '(?:a|b)aa(?:aa|bb)cc(?:a|b)' abc.txt
PCRE interp no match: 305.05279 ms elapsed (1 matches found, 5 repeated times).
PCRE JIT no match: 58.37427 ms elapsed (1 matches found, 5 repeated times).
PCRE2 interp no match: 428.98801 ms elapsed (1 matches found, 5 repeated times).
PCRE2 JIT no match: 58.44519 ms elapsed (1 matches found, 5 repeated times).
RE2 PartialMatch no match: 73.70936 ms elapsed (1 matches found, 5 repeated times).
SRegex DFA proto no match: 16.30375 ms elapsed (1 matches found, 5 repeated times).

Case 11

$ ./bench '(?:a|b)aa(?:aa|bb)cc(?:a|b)abcabcabd' rand-abc.txt
PCRE interp no match: 274.73602 ms elapsed (0 matches found, 5 repeated times).
PCRE JIT no match: 71.58887 ms elapsed (0 matches found, 5 repeated times).
PCRE2 interp no match: 363.80651 ms elapsed (0 matches found, 5 repeated times).
PCRE2 JIT no match: 72.23492 ms elapsed (0 matches found, 5 repeated times).
RE2 PartialMatch no match: 54.23838 ms elapsed (0 matches found, 5 repeated times).
SRegex DFA proto no match: 47.04464 ms elapsed (0 matches found, 5 repeated times).

Case 12

$ ./bench '(a|b)aa(aa|bb)cc(a|b)abcabcabc' abc.txt
PCRE interp no match: 381.13191 ms elapsed (0 matches found, 5 repeated times).
PCRE JIT no match: 61.34844 ms elapsed (0 matches found, 5 repeated times).
PCRE2 interp no match: 545.03249 ms elapsed (0 matches found, 5 repeated times).
PCRE2 JIT no match: 60.67951 ms elapsed (0 matches found, 5 repeated times).
RE2 PartialMatch no match: 73.62965 ms elapsed (0 matches found, 5 repeated times).
SRegex DFA proto no match: 18.04628 ms elapsed (0 matches found, 5 repeated times).

Case 13

$ ./bench '(a|b)aa(aa|bb)cc(a|b)abcabcabc' rand-abc.txt
PCRE interp no match: 328.05416 ms elapsed (0 matches found, 5 repeated times).
PCRE JIT no match: 75.50222 ms elapsed (0 matches found, 5 repeated times).
PCRE2 interp no match: 441.32162 ms elapsed (0 matches found, 5 repeated times).
PCRE2 JIT no match: 75.71060 ms elapsed (0 matches found, 5 repeated times).
RE2 PartialMatch no match: 54.64334 ms elapsed (0 matches found, 5 repeated times).
SRegex DFA proto no match: 47.55219 ms elapsed (0 matches found, 5 repeated times).

Case 14

$ ./bench 'd[abc]*?d' delim.txt
PCRE interp no match: 11.04995 ms elapsed (0 matches found, 5 repeated times).
PCRE JIT no match: 9.35393 ms elapsed (0 matches found, 5 repeated times).
PCRE2 interp no match: 8.46070 ms elapsed (0 matches found, 5 repeated times).
PCRE2 JIT no match: 9.44652 ms elapsed (0 matches found, 5 repeated times).
RE2 PartialMatch no match: 32.49024 ms elapsed (0 matches found, 5 repeated times).
SRegex DFA proto no match: 4.68242 ms elapsed (0 matches found, 5 repeated times).

Case 15

$ ./bench 'd.*?d' delim.txt
PCRE interp error: -8: 61.76660 ms elapsed (0 matches found, 5 repeated times).
PCRE JIT error: -8: 15.30574 ms elapsed (0 matches found, 5 repeated times).
PCRE2 interp error: -47: 83.83281 ms elapsed (0 matches found, 5 repeated times).
PCRE2 JIT error: -47: 15.36167 ms elapsed (0 matches found, 5 repeated times).
RE2 PartialMatch no match: 32.38806 ms elapsed (0 matches found, 5 repeated times).
SRegex DFA proto no match: 0.46913 ms elapsed (0 matches found, 5 repeated times).

Case 16

$ ./bench 'd.*d' delim.txt
PCRE interp error: -8: 55.12419 ms elapsed (0 matches found, 5 repeated times).
PCRE JIT error: -8: 18.66527 ms elapsed (0 matches found, 5 repeated times).
PCRE2 interp error: -47: 77.83466 ms elapsed (0 matches found, 5 repeated times).
PCRE2 JIT no match: 6.97114 ms elapsed (0 matches found, 5 repeated times).
RE2 PartialMatch no match: 33.04543 ms elapsed (0 matches found, 5 repeated times).
SRegex DFA proto no match: 0.45931 ms elapsed (0 matches found, 5 repeated times).

Case 17

$ ./bench2 '^Twain' mtent12.txt
PCRE interp no match: 25.67913 ms elapsed (100 matches found, 5 repeated times).
PCRE JIT no match: 10.01252 ms elapsed (100 matches found, 5 repeated times).
PCRE2 interp no match: 25.90539 ms elapsed (100 matches found, 5 repeated times).
PCRE2 JIT no match: 9.94656 ms elapsed (100 matches found, 5 repeated times).
RE2 PartialMatch no match: 63.06612 ms elapsed (100 matches found, 5 repeated times).
SRegex DFA proto no match: 9.71002 ms elapsed (100 matches found, 5 repeated times).

Case 18

$ ./bench 'Twain' mtent12.txt
PCRE interp no match: 7.30472 ms elapsed (2388 matches found, 5 repeated times).
PCRE JIT no match: 8.87318 ms elapsed (2388 matches found, 5 repeated times).
PCRE2 interp no match: 2.75217 ms elapsed (2388 matches found, 5 repeated times).
PCRE2 JIT no match: 8.36878 ms elapsed (2388 matches found, 5 repeated times).
RE2 PartialMatch no match: 2.39989 ms elapsed (2388 matches found, 5 repeated times).
SRegex DFA proto no match: 1.77124 ms elapsed (2388 matches found, 5 repeated times).

Case 19

$ ./bench '(?i)Twain' mtent12.txt
PCRE interp no match: 42.34333 ms elapsed (2657 matches found, 5 repeated times).
PCRE JIT no match: 22.74309 ms elapsed (2657 matches found, 5 repeated times).
PCRE2 interp no match: 45.36183 ms elapsed (2657 matches found, 5 repeated times).
PCRE2 JIT no match: 22.48715 ms elapsed (2657 matches found, 5 repeated times).
RE2 PartialMatch no match: 64.27031 ms elapsed (2657 matches found, 5 repeated times).
SRegex DFA proto no match: 19.21937 ms elapsed (2657 matches found, 5 repeated times).

Case 20

$ ./bench '[a-z]shing' mtent12.txt
PCRE interp no match: 293.13568 ms elapsed (1877 matches found, 5 repeated times).
PCRE JIT no match: 67.96416 ms elapsed (1877 matches found, 5 repeated times).
PCRE2 interp no match: 323.71290 ms elapsed (1877 matches found, 5 repeated times).
PCRE2 JIT no match: 68.79201 ms elapsed (1877 matches found, 5 repeated times).
RE2 PartialMatch no match: 96.62861 ms elapsed (1877 matches found, 5 repeated times).
SRegex DFA proto no match: 49.59758 ms elapsed (1877 matches found, 5 repeated times).

Case 21

$ ./bench 'Huck[a-zA-Z]+|Saw[a-zA-Z]+' mtent12.txt
PCRE interp no match: 16.14250 ms elapsed (396 matches found, 5 repeated times).
PCRE JIT no match: 11.03352 ms elapsed (396 matches found, 5 repeated times).
PCRE2 interp no match: 16.49485 ms elapsed (396 matches found, 5 repeated times).
PCRE2 JIT no match: 11.27589 ms elapsed (396 matches found, 5 repeated times).
RE2 PartialMatch no match: 55.15386 ms elapsed (396 matches found, 5 repeated times).
SRegex DFA proto no match: 11.09284 ms elapsed (396 matches found, 5 repeated times).

Case 22

$ ./bench '\b\w+nn\b' mtent12.txt
PCRE interp no match: 388.51288 ms elapsed (359 matches found, 5 repeated times).
PCRE JIT no match: 156.02943 ms elapsed (359 matches found, 5 repeated times).
PCRE2 interp no match: 485.25904 ms elapsed (359 matches found, 5 repeated times).
PCRE2 JIT no match: 78.03511 ms elapsed (359 matches found, 5 repeated times).
RE2 PartialMatch no match: 64.32402 ms elapsed (359 matches found, 5 repeated times).
SRegex DFA proto no match: 52.61633 ms elapsed (359 matches found, 5 repeated times).

Case 23

$ ./bench3 '[a-q][^u-z]{13}x' mtent12.txt
PCRE interp no match: 358.07903 ms elapsed (4929 matches found, 5 repeated times).
PCRE JIT no match: 136.84579 ms elapsed (4929 matches found, 5 repeated times).
PCRE2 interp no match: 399.47415 ms elapsed (4929 matches found, 5 repeated times).
PCRE2 JIT no match: 127.62715 ms elapsed (4929 matches found, 5 repeated times).
RE2 PartialMatch no match: 15294.67469 ms elapsed (4929 matches found, 1 repeated times).
SRegex DFA proto no match: 172.00279 ms elapsed (4929 matches found, 5 repeated times).

Case 24

$ ./bench 'Tom|Sawyer|Huckleberry|Finn' mtent12.txt
PCRE interp no match: 20.52201 ms elapsed (3015 matches found, 5 repeated times).
PCRE JIT no match: 19.95426 ms elapsed (3015 matches found, 5 repeated times).
PCRE2 interp no match: 22.32097 ms elapsed (3015 matches found, 5 repeated times).
PCRE2 JIT no match: 20.21049 ms elapsed (3015 matches found, 5 repeated times).
RE2 PartialMatch no match: 56.98331 ms elapsed (3015 matches found, 5 repeated times).
SRegex DFA proto no match: 17.18599 ms elapsed (3015 matches found, 5 repeated times).

Case 25

$ ./bench '(?i)Tom|Sawyer|Huckleberry|Finn' mtent12.txt
PCRE interp no match: 184.53599 ms elapsed (4820 matches found, 5 repeated times).
PCRE JIT no match: 60.44365 ms elapsed (4820 matches found, 5 repeated times).
PCRE2 interp no match: 250.33581 ms elapsed (4820 matches found, 5 repeated times).
PCRE2 JIT no match: 58.68829 ms elapsed (4820 matches found, 5 repeated times).
RE2 PartialMatch no match: 82.00404 ms elapsed (4820 matches found, 5 repeated times).
SRegex DFA proto no match: 63.29151 ms elapsed (4820 matches found, 5 repeated times).

Case 26

$ ./bench '.{0,2}(Tom|Sawyer|Huckleberry|Finn)' mtent12.txt
PCRE interp no match: 2256.83746 ms elapsed (3015 matches found, 5 repeated times).
PCRE JIT no match: 253.04546 ms elapsed (3015 matches found, 5 repeated times).
PCRE2 interp no match: 3443.05948 ms elapsed (3015 matches found, 5 repeated times).
PCRE2 JIT no match: 226.90719 ms elapsed (3015 matches found, 5 repeated times).
RE2 PartialMatch no match: 65.78608 ms elapsed (3015 matches found, 5 repeated times).
SRegex DFA proto no match: 17.06100 ms elapsed (3015 matches found, 5 repeated times).

Case 27

$ ./bench '.{2,4}(Tom|Sawyer|Huckleberry|Finn)' mtent12.txt
PCRE interp no match: 2444.50379 ms elapsed (2727 matches found, 5 repeated times).
PCRE JIT no match: 279.14357 ms elapsed (2727 matches found, 5 repeated times).
PCRE2 interp no match: 3434.20850 ms elapsed (2727 matches found, 5 repeated times).
PCRE2 JIT no match: 253.71051 ms elapsed (2727 matches found, 5 repeated times).
RE2 PartialMatch no match: 65.78567 ms elapsed (2727 matches found, 5 repeated times).
SRegex DFA proto no match: 17.54060 ms elapsed (2727 matches found, 5 repeated times).

Case 28

$ ./bench '[a-zA-Z]+ing' mtent12.txt
PCRE interp no match: 597.70031 ms elapsed (95863 matches found, 5 repeated times).
PCRE JIT no match: 159.41107 ms elapsed (95863 matches found, 5 repeated times).
PCRE2 interp no match: 774.46135 ms elapsed (95863 matches found, 5 repeated times).
PCRE2 JIT no match: 58.40116 ms elapsed (95863 matches found, 5 repeated times).
RE2 PartialMatch no match: 149.33379 ms elapsed (95863 matches found, 5 repeated times).
SRegex DFA proto no match: 49.17325 ms elapsed (95863 matches found, 5 repeated times).

Case 29

$ ./bench '\s[a-zA-Z]{0,12}ing\s' mtent12.txt
PCRE interp no match: 281.35215 ms elapsed (67810 matches found, 5 repeated times).
PCRE JIT no match: 94.36998 ms elapsed (67810 matches found, 5 repeated times).
PCRE2 interp no match: 334.31835 ms elapsed (67810 matches found, 5 repeated times).
PCRE2 JIT no match: 78.26358 ms elapsed (67810 matches found, 5 repeated times).
RE2 PartialMatch no match: 112.85631 ms elapsed (67810 matches found, 5 repeated times).
SRegex DFA proto no match: 66.26479 ms elapsed (67810 matches found, 5 repeated times).

Case 30

$ ./bench '([A-Za-z]awyer|[A-Za-z]inn)\s' mtent12.txt
PCRE interp no match: 564.25083 ms elapsed (313 matches found, 5 repeated times).
PCRE JIT no match: 90.06861 ms elapsed (313 matches found, 5 repeated times).
PCRE2 interp no match: 731.48989 ms elapsed (313 matches found, 5 repeated times).
PCRE2 JIT no match: 103.77871 ms elapsed (313 matches found, 5 repeated times).
RE2 PartialMatch no match: 93.76083 ms elapsed (313 matches found, 5 repeated times).
SRegex DFA proto no match: 57.78990 ms elapsed (313 matches found, 5 repeated times).

Case 31

$ ./bench $'["\'][^"\']{0,30}[?!\.]["\']' mtent12.txt
PCRE interp no match: 35.52328 ms elapsed (9857 matches found, 5 repeated times).
PCRE JIT no match: 19.75594 ms elapsed (9857 matches found, 5 repeated times).
PCRE2 interp no match: 41.24986 ms elapsed (9857 matches found, 5 repeated times).
PCRE2 JIT no match: 17.43314 ms elapsed (9857 matches found, 5 repeated times).
RE2 PartialMatch no match: 133.57071 ms elapsed (9849 matches found, 5 repeated times).
SRegex DFA proto no match: 13.37160 ms elapsed (9857 matches found, 5 repeated times).