Replaced UglifyJS2 with Traceur for fair comparison of ES6-enabled parsers.
This commit is contained in:
parent
7aab3539ce
commit
8b19246615
@ -4,7 +4,7 @@
|
||||
<title>Acorn benchmark</title>
|
||||
<script src="../acorn.js"></script>
|
||||
<script src="compare/esprima.js"></script>
|
||||
<script src="compare/uglifyjs2.js"></script>
|
||||
<script src="compare/traceur.js"></script>
|
||||
<script src="jquery-string.js"></script>
|
||||
<script src="codemirror-string.js"></script>
|
||||
<style>
|
||||
@ -15,11 +15,11 @@
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<h1>Acorn/Esprima/UglifyJS2 speed comparison</h1>
|
||||
<h1>Acorn/Esprima/Traceur speed comparison</h1>
|
||||
|
||||
<p>This will run each of the three parsers on the source code of
|
||||
<p>This will run each of the three ES6 parsers on the source code of
|
||||
jQuery 1.6.4 and CodeMirror 3.0b1 for two seconds, and show a table
|
||||
indicating the number of lines parsed per second. Note that UglifyJS
|
||||
indicating the number of lines parsed per second. Note that Traceur
|
||||
always stores location data, and is thus not fairly compared by the
|
||||
benchmark <em>without</em> location data.<p>
|
||||
|
||||
@ -35,28 +35,34 @@ numbers.</p>
|
||||
<span id="running"></span>
|
||||
|
||||
<script>
|
||||
var sourceFileName = 'source.js';
|
||||
|
||||
function runAcorn(code, locations) {
|
||||
acorn.parse(code, {ecmaVersion: 6, locations: locations});
|
||||
acorn.parse(code, {ecmaVersion: 6, locations: locations, sourceFile: sourceFileName});
|
||||
}
|
||||
function runEsprima(code, locations) {
|
||||
esprima.parse(code, {loc: locations});
|
||||
esprima.parse(code, {loc: locations, source: sourceFileName});
|
||||
}
|
||||
function runUglifyJS(code) {
|
||||
uglifyjs.parse(code);
|
||||
function runTraceur(code) {
|
||||
var file = new traceur.syntax.SourceFile(sourceFileName, code);
|
||||
var parser = new traceur.syntax.Parser(file);
|
||||
parser.parseScript();
|
||||
}
|
||||
|
||||
var totalLines = codemirror30.split("\n").length + jquery164.split("\n").length;
|
||||
|
||||
var nowHost = (typeof performance === 'object' && 'now' in performance) ? performance : Date;
|
||||
|
||||
function benchmark(runner, locations) {
|
||||
// Give it a chance to warm up (first runs are usually outliers)
|
||||
runner(jquery164, locations);
|
||||
runner(codemirror30, locations);
|
||||
var t0 = +new Date, t1, lines = 0;
|
||||
var t0 = nowHost.now(), t1, lines = 0;
|
||||
for (;;) {
|
||||
runner(jquery164, locations);
|
||||
runner(codemirror30, locations);
|
||||
lines += totalLines;
|
||||
t1 = +new Date;
|
||||
t1 = nowHost.now();
|
||||
if (t1 - t0 > 2000) break;
|
||||
}
|
||||
return lines / ((t1 - t0) / 1000);
|
||||
@ -75,7 +81,7 @@ numbers.</p>
|
||||
running.innerHTML = "Running benchmark...";
|
||||
var data = [{name: "Acorn", runner: runAcorn},
|
||||
{name: "Esprima", runner: runEsprima},
|
||||
{name: "UglifyJS2", runner: runUglifyJS}];
|
||||
{name: "Traceur", runner: runTraceur}];
|
||||
if (acornOnly) data.length = 1;
|
||||
var pos = 0;
|
||||
function next() {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user