[antlr-interest] ANTLR performance
Jim Idle
jimi at temporal-wave.com
Thu Jan 15 10:20:33 PST 2009
Jan Obdržálek wrote:
> Hello,
>
> for our student research project we implemented a C grammar in ANTLR
> 3.1. (The grammar fully implements ANSI C99, and mostly implements the
> GNU C extensions - the notable exception being the attributes, which
> are a real pain.) However we found the performance of the parser to be
> a bit lacking. We therefore ran some tests. In addition to the default
> Java target, we modified the grammar for the C target. The results
> were then compared to the results obtained by using the GNU C
> compiler. This is a fair comparison, since gcc also uses a top-down
> recursive parser (although hand-coded). Actually the test is tougher
> on gcc, since gcc does full compilation, compared to just building the
> AST in the case of ANTLR.
>
> The results can be summarized as follows (more details about the test
> at the end of this post):
>
> - ANTLR/Java is obviously the slowest one [and there is a serious
> start-up/close-down overhead]
> - ANTLR/C is faster, but still miles behind the gcc
Looking at your gprof file, it claims that the function call
setCharPositionInLine() is called 4 times and takes 0.67 seconds,
however this function is just this:
static void setCharPositionInLine (pANTLR3_COMMON_TOKEN
token, ANTLR3_INT32 pos)
{
token->charPosition = pos;
}
So, I am having a hard time buying that. Try kcachegrind and see if this
gives a different perspective, but as I say, we need to see the grammar
really. I also suggest trying the beta 3.1.2 runtime which is in
perforce/fisheye, though this probably means you need to use a current
build of the ANTLR tool, which you can get from hudson:
www.antlr.org/hudson.
Jim
More information about the antlr-interest
mailing list