Friday, October 30, 2015

Parsing JavaScript with Esprima vs ANTLR

My original thought is that, the compilation for ANTLR 4 Esmascript (I am using C# target)
(https://github.com/antlr/grammars-v4/blob/master/ecmascript/ECMAScript.g4)
should be faster than Esprima
(http://esprima.org/)

It turns out that it is not.

I use jQuery.Mobile 1.4.2 to experiment:
ANTLR 4 makes use of 1 minute,
while
Esprima only makes use of 100 milliseconds.

Esprima is much faster than ANTLR 4.

Not only I have observed this, I have found some complaints of the speed of ANTLR 4 for JavaScript by other people:
https://groups.google.com/forum/#!msg/antlr-discussion/AUN7BLSDIzo/KG5MQ95Us9gJ

If you are gonna decide which to use, I am here to save your time: choose Esprima.