Created
October 11, 2012 16:04
-
-
Save mishoo/3873423 to your computer and use it in GitHub Desktop.
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
#! /usr/local/bin/node | |
var esprima = require("esprima"); | |
var acorn = require("acorn"); | |
var u2 = require("uglify-js2"); | |
var fs = require("fs"); | |
var file = process.argv[2]; | |
var code = fs.readFileSync(file, "utf8"); | |
function time_it(name, cont) { | |
var t1 = new Date().getTime(); | |
var ret = cont(); | |
var spent = new Date().getTime() - t1; | |
console.log("%s: %s", name, (spent / 1000).toFixed(3)); | |
return ret; | |
} | |
time_it("esprima", function(){ | |
esprima.parse(code, { loc: true, comment: true }); | |
}); | |
time_it("uglifyjs2", function(){ | |
u2.parse(code); | |
}); | |
time_it("acorn", function(){ | |
acorn.parse(code, { locations: true, trackComments: true }); | |
}); | |
// $ cat `~/work/thelib/bin/list-scripts.pl` | jsparsers-compare.js /dev/stdin | |
// esprima: 0.941 | |
// uglifyjs2: 0.261 | |
// acorn: 0.212 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment