Created
November 11, 2017 08:20
-
-
Save TheLarkInn/8b1c5f275b3ae1c604abab78c12606ef to your computer and use it in GitHub Desktop.
benchparse.js
This file contains hidden or 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
const fs = require('fs'); | |
const path = require('path'); | |
const Benchmark = require('benchmark'); | |
const suite = new Benchmark.Suite; | |
const ts = require('typescript'); | |
const acorn = require('acorn'); | |
const babylon = require('babylon'); | |
const parseWithTypeScript = (sourcefile) => ts.createSourceFile('parse-me.js', sourcefile, ts.ScriptTarget.Latest, false, ts.ScriptKind.JS); | |
const parseWithAcorn = (sourcefile) => acorn.parse(sourcefile, {sourceType: 'module'}); | |
const parseWithBabylon = (sourcefile) => babylon.parse(sourcefile, { sourceType: 'module' }); | |
const scriptSource = fs.readFileSync(path.join(__dirname, 'node_modules', 'typescript', 'lib', 'typescript.js')).toString(); | |
suite | |
.add('acorn parse', () => parseWithAcorn(scriptSource)) | |
.add('typescript parse', () => parseWithTypeScript(scriptSource)) | |
.add('babylon parse', () => parseWithBabylon(scriptSource)) | |
.on('cycle', (event) => {console.log(String(event.target))}) | |
.on('complete', function (){ console.log('Fastest is ' + this.filter('fastest').map('name')) }) | |
.run({'asnyc': true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment