[antlr-interest] attempt to compare antlr vs bison/flex performance

Arnulf Heller aheller at gmx.at
Fri Dec 21 13:10:13 PST 2007


Hi,

a point that you might also consider is the performance of the Lexer alone.

As far as I can remember there were statements in this mailing list 
that the ANTLR Lexer performance is not mind-blasting :-)
These folks also found ways to use Flex for the lexing part with good 
speed improvements.

This gives the power of ANTLR parsing and the speed of Flex lexing :-)

Maybe you manage to separate your benchmark into the lexing and full 
parsing part.
With ANTLR that should be perfectly possible because you can use the 
Lexer "standalone" and pop tokens out.
If you are able to do that with Flex too (and I assume that is 
possible but my Flex experience is rusty) you can compare the lexing 
and parsing processing overhead for both approaches.

It might also prove difficult to compare the performance due to 
caching of the file in the OS, the CPU, ...
I assume it's good advice to repeat the test several times an 
alternating the two competitors.

In case you have reproducible results, please post it - I'm also curious :-)


At 00:22 20.12.2007, you wrote:
>Hello,
>
>In an effort to compare antlr and bison/flex parsers, I did the 
>following exercise:
>
>- found and compiled bison/flex "C" language parser from the 
>following location:
>    ftp://ftp.uu.net/usenet/net.sources/ansi.c.grammar.Z
>- downloaded and compiled antlr3 implementation of "C" language 
>parser from this directory in antlr3 examples:
>   antlr/examples-v3/C/C
>- preprocessed a "C" language file and stripped it such that both 
>parser would pass it through (mostly minor changes)
>- compared runtime for each parser
>
>
>The results of this exercise show that the antlr parser is ~9 times 
>slower than the flex/bison parser. I have used the same version of 
>GNU C compiler for both parsers, with exact same compile options.
>
>Although the grammar definitions come from different sources, I 
>still think this exercise gives a general idea about performance 
>differences of these parsers. Could anyone please tell me if this is 
>an expected runtime difference or you think I could do some 
>optimizations to get faster performance from antlr3.
>
>I can send the complete code I used for both parsers, or any parts 
>of it, if necessary. Just tell me which part would be of interest.
>
>Thanks,
>Minas



More information about the antlr-interest mailing list