Regular Expression Performance Comparison

The Boost and GRETA regular expression libraries have slightly different interfaces, and it has been suggested that GRETA's interface allows for a more efficient implementation. The following tables provide comparisons between:

GRETA.

The Boost regex library.

Henry Spencer's regular expression library - this is provided for comparison as a typical non-backtracking implementation.

Details

Machine: Intel Pentium 4 2.8GHz PC.

Compiler: %compiler%.

C++ Standard Library: %library%.

OS: %os%.

Boost version: %boost%.

PCRE version: %pcre%.

As ever care should be taken in interpreting the results, only sensible regular expressions (rather than pathological cases) are given, most are taken from the Boost regex examples, or from the Library of Regular Expressions. In addition, some variation in the relative performance of these libraries can be expected on other machines - as memory access and processor caching effects can be quite large for most finite state machine algorithms.

Comparison 1: Long Search

For each of the following regular expressions the time taken to find all occurrences of the expression within a long English language text was measured (mtent12.txt from Project Gutenberg, 19Mb). 

%long_twain_search%

Comparison 2: Medium Sized Search

For each of the following regular expressions the time taken to find all occurrences of the expression within a medium sized English language text was measured (the first 50K from mtent12.txt). 

%short_twain_search%

Comparison 3: C++ Code Search

For each of the following regular expressions the time taken to find all occurrences of the expression within the C++ source file boost/crc.hpp was measured. 

%code_search%

Comparison 4: HTML Document Search

For each of the following regular expressions the time taken to find all occurrences of the expression within the html file libs/libraries.htm was measured. 

%html_search%

Comparison 3: Simple Matches

For each of the following regular expressions the time taken to match against the text indicated was measured. 

%short_matches%


Copyright John Maddock April 2003, all rights reserved.