JavaScript Parsing Libraries Benchmark

A JSON Parser was implemented using each of these Parsing Libraries (Generators/Combinators/DSLs):

  1. Chevrotain Parsing DSL implementation

  2. Parsimmon Parser Combinator implementation

  3. ANTLR4 Parser Generator grammar -> generated code

  4. Myna Parsing Library implementation

  5. PEG.js Parser Generator grammar -> generated code

  6. Jison parser Generator grammar -> generated code

  7. Nearley Parser Generator grammar -> generated code with Moo Lexer

  8. Ohm-js Parser Library grammar -> parser

These are hand-built JSON parsers to compare against generic generators/libraries/DSLS

  1. The browser's JSON.parse() for comparison. [implementation]

  2. Oboe JSON Parser for comparison [implementation]

  3. Substack Jsonify JSON Parser for comparison [implementation]

The JSON Grammar was used because it is simple to implement, simple to compare and is often already available as a sample grammar for most parsing tools.

The input sample for the benchmark is a ~1,000 lines JSON file generated by json-generator.

See the benchmark methodology for details on what is being tested and how.

The Chevrotain and Antlr Libraries can either produce a Parse Tree (with Visitor / listener) or use embedded actions in the grammar. Thus they are measured in both scenarios ("-PT" means Parse Tree variant).

Benchmarking is done using the benchmark.js library.

The entire source code for this benchmark can be found in this github repository.

 
Library
Ops/sec
Relative Speed
?
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Browser