forked from acornjs/acorn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows to run up-to-date parsers directly from console or browser against prebundled popular frameworks and outputs results in a nice table. Browser version now uses a Web Worker to avoid blocking UI while benchmark is running and improve stability of numbers. No locations versions were removed (at least for now) as most parsers don't support it and it's not really the most common use-case to optimise for (most tooling that depends on us is generating source maps and such). Also, benchmark code now targets latest stable versions of browsers / Node.js (relying on Web Workers, Promises and fetch) - while we continue to support older ones through tests, it doesn't seem worth it to target for them performance-wise and reduce code quality or transpile benchmark itself.
- Loading branch information
Showing
16 changed files
with
120,561 additions
and
42,417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/node_modules | ||
node_modules | ||
/.tern-port | ||
/local | ||
/bin/acorn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict'; | ||
|
||
const isWorker = typeof importScripts !== 'undefined'; | ||
|
||
if (isWorker) { | ||
importScripts('https://unpkg.com/esprima'); | ||
importScripts('../../dist/acorn.js'); | ||
var acornDev = acorn; | ||
var acorn = undefined; | ||
importScripts('https://unpkg.com/acorn'); | ||
importScripts('https://unpkg.com/traceur/bin/traceur.js'); | ||
importScripts('https://unpkg.com/typescript'); | ||
} else { | ||
var fs = require('fs'); | ||
var esprima = require('esprima'); | ||
var acornDev = require('../../dist/acorn'); | ||
var acorn = require('acorn'); | ||
require('traceur'); // yeah, it creates a global... | ||
var ts = require('typescript'); | ||
} | ||
|
||
var parsers = { | ||
[`Acorn (dev)`](s) { | ||
acornDev.parse(s, { locations: true }); | ||
}, | ||
[`Acorn ${acorn.version}`](s) { | ||
acorn.parse(s, { locations: true }); | ||
}, | ||
[`Esprima ${esprima.version}`](s) { | ||
esprima.parse(s, { loc: true }); | ||
}, | ||
[`TypeScript ${ts.version}`](s) { | ||
ts.createSourceFile('source.js', s, ts.ScriptTarget.ES6); | ||
}, | ||
[`Traceur ${traceur.loader.TraceurLoader.prototype.version}`](s) { | ||
var file = new traceur.syntax.SourceFile('source.js', s); | ||
var parser = new traceur.syntax.Parser(file); | ||
parser.parseScript(); | ||
}, | ||
}; | ||
|
||
var parserNames = Object.keys(parsers); | ||
|
||
var inputNames = [ | ||
'angular.js', | ||
'backbone.js', | ||
'ember.js', | ||
'jquery.js', | ||
'react-dom.js', | ||
'react.js' | ||
]; | ||
|
||
var inputs = Promise.all(inputNames.map(name => { | ||
name = `fixtures/${name}`; | ||
|
||
if (isWorker) { | ||
return fetch(name).then(response => response.text()); | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(`${__dirname}/${name}`, 'utf-8', (err, data) => { | ||
err ? reject(err) : resolve(data); | ||
}); | ||
}); | ||
} | ||
})); | ||
|
||
if (!isWorker) { | ||
module.exports = { | ||
parsers, | ||
parserNames, | ||
inputs, | ||
inputNames | ||
}; | ||
} |
Oops, something went wrong.