Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yet another performance benchmark (egemadra's recursive-descent parser builder) #2085

Open
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
"gen_peggy": "peggy -e peggyJsonLexerAndParser --format globals -o ./performance/jsonParsers/peggy/peggy_jison_parser.js ./performance/jsonParsers/peggy/json.peggy"
},
"devDependencies": {
"prettier" : "3.3.3",
"fs-extra": "^5.0.0",
"peggy": "4.1.1",
"antlr4": "4.13.2",
"esbuild": "0.24.0",
"fs-extra": "^5.0.0",
"gitty": "^3.3.2",
"jison": "*",
"jison-lex": "*",
"jsonfile": "^2.2.3",
"lodash": "^3.10.1",
"nearley": "2.20.1",
"peggy": "4.1.1",
"prettier": "3.3.3",
"recursive-descent": "^0.1.2",
"wrench": "^1.5.8"
},
"private": true
Expand Down
38 changes: 30 additions & 8 deletions performance/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@



<script src="jsonParsers/browser/browser_json_parser.js"></script>



Expand Down Expand Up @@ -46,7 +45,7 @@ <h2>JavaScript Parsing Libraries Benchmark</h2>
<li><p><a rel="nofollow" href="http://www.antlr.org/">ANTLR4</a> Parser Generator
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/antlr/JSON_ANTLR.g4">grammar</a>
->
-&gt;
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/antlr/JSON_ANTLRParser.js">generated
code</a>
Expand All @@ -56,7 +55,7 @@ <h2>JavaScript Parsing Libraries Benchmark</h2>
<a rel="nofollow" href="https://peggyjs.org">Peggy</a> Parser Generator
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/peggy/json.peggy">grammar</a>
->
-&gt;
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/peggy/peggy_jison_parser.js">generated
code</a>
Expand All @@ -66,7 +65,7 @@ <h2>JavaScript Parsing Libraries Benchmark</h2>
<i>abandoned:</i> <s><a rel="nofollow" href="https://github.com/pegjs/pegjs">PEG.js</a> Parser Generator</s>
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/pegjs/json.pegjs">grammar</a>
->
-&gt;
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/pegjs/pegjs_jison_parser.js">generated
code</a>
Expand All @@ -75,7 +74,7 @@ <h2>JavaScript Parsing Libraries Benchmark</h2>
<li><p><a rel="nofollow" href="https://github.com/zaach/jison">Jison</a> parser Generator
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/jison/jsonParserGrammar.js">grammar</a>
->
-&gt;
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/jison/jisonParser.js">generated
code</a>
Expand All @@ -86,7 +85,7 @@ <h2>JavaScript Parsing Libraries Benchmark</h2>
<a rel="nofollow" href="http://nearley.js.org/">Nearley</a> Parser Generator
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/nearley/json_grammar_tokenizer.ne">grammar</a>
->
-&gt;
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/nearley/nearley_json_parser_tokenizer.js">generated
code</a>
Expand All @@ -100,11 +99,17 @@ <h2>JavaScript Parsing Libraries Benchmark</h2>
<a rel="nofollow" href="https://github.com/cdglabs/ohm">Ohm-js</a> Parser Library
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/ohm/ohm_json_grammar.js">grammar</a>
->
-&gt;
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/ohm/ohm_json_parser.js">parser</a>
</p></li>

<li><p>
<a rel="nofollow" href="https://github.com/egemadra/recursive-descent">Recursive-Descent</a> Parser Builder
<a rel="nofollow"
href="https://github.com/Chevrotain/chevrotain/blob/gh-pages/performance/jsonParsers/recursive-descent/json.grammar">grammar</a>
</p></li>

</ol>

<p>
Expand Down Expand Up @@ -263,6 +268,18 @@ <h2>JavaScript Parsing Libraries Benchmark</h2>
<div class="benchInclude"><input type="checkbox"/></div>

</div>

<div class="dataRow RecursiveDescent">

<div class="benchName"><a rel="nofollow" href="https://github.com/egemadra/recursive-descent">Recursive-Descent</a></div>
<div class="benchRate">
<div class="value">&nbsp;</div>
<div class="delta">&nbsp;</div>
</div>
<div class="benchSpeed">&nbsp;</div>
<div class="benchInclude"><input type="checkbox"/></div>

</div>
</div>
</div>
<canvas id="parsersResultChart"></canvas>
Expand Down Expand Up @@ -293,11 +310,12 @@ <h2>JavaScript Parsing Libraries Benchmark</h2>
var parsimmonFrame = includeTestIFrame("parsimmon", "./jsonParsers/parsimmon/parsimmon.html")
var pegjsFrame = includeTestIFrame("pegjs", "./jsonParsers/pegjs/pegjs.html")
var peggyFrame = includeTestIFrame("peggy", "./jsonParsers/peggy/peggy.html")
var recursiveDescentFrame = includeTestIFrame("recursive-descent", "./jsonParsers/recursive-descent/recursive-descent.html")

$("iframe").css("visibility", "hidden")

var styleCss = _.find(document.styleSheets, function (styleSheet) {
return _.endsWith(styleSheet.href, "performance/style.css");
return _.endsWith(styleSheet.href, "/style.css");
})

if (styleCss === undefined) {
Expand Down Expand Up @@ -440,6 +458,10 @@ <h2>JavaScript Parsing Libraries Benchmark</h2>

Ohm: function (suite) {
addTest(suite, 'Ohm', ohmFrame.parse)
},

RecursiveDescent: function (suite) {
addTest(suite, 'RecursiveDescent', recursiveDescentFrame.parse)
}
}

Expand Down
44 changes: 44 additions & 0 deletions performance/jsonParsers/recursive-descent/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { BNFParser, Parser } from './module.js';

// from: https://github.com/egemadra/recursive-descent/blob/master/examples/json/json.grammar
// based on: https://github.com/antlr/grammars-v4/blob/master/json/JSON.g4
const grammar = `
ignore = ~[ \t\n\r]+~ ;

false = 'false';
true = 'true';
null = 'null';

program : value ;

value : string | number | object | array | true | false | null ;

object : '{' object_body? '}' ;

object_body : pair <(',' pair)* ;

pair : string ':' value ;

array : '[' array_body? ']' ;

array_body : value <(',' value)* ;

string = ~"((\\u[A-Fa-f0-9]{4})|[^\\"\u0000-\u001F]|(\\[bfnrt"\\]))*"~ ;

number = ~\-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+\-]?(0|[1-9][0-9]*))?~ ;
`;

const bnfParser = new BNFParser(grammar);
const rules = bnfParser.parse();

//Ask parser to not to give us tokens that don't represent a value
//This results in much cleaner and smaller tree.
const options = {
exclude: ["{", "}", "[", "]", ",", ':']
};

window.parse = function(program) {
//Parse the program
const parser = new Parser(rules, program, options);
const root = parser.parse();
};
26 changes: 26 additions & 0 deletions performance/jsonParsers/recursive-descent/json.grammar
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//based on
//https://github.com/antlr/grammars-v4/blob/master/json/JSON.g4

ignore = ~[ \t\n\r]+~ ;

false = 'false';
true = 'true';
null = 'null';

program : value ;

value : string | number | object | array | true | false | null ;

object : '{' object_body? '}' ;

object_body : pair <(',' pair)* ;

pair : string ':' value ;

array : '[' array_body? ']' ;

array_body : value <(',' value)* ;

string = ~"((\\u[A-Fa-f0-9]{4})|[^\\"\u0000-\u001F]|(\\[bfnrt"\\]))*"~ ;

number = ~\-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+\-]?(0|[1-9][0-9]*))?~ ;
Loading