swc/crates/swc_webpack_ast/scripts/bench.js
Donny/강동윤 c2bbdbe9d6
feat(webpack): Add ast reducer ()
swc_estree_compat:
 - Fix stack overflow related to object patterns.

swc_webpack_}ast:
 - Implement AST reducer.
2021-11-26 15:04:41 +09:00

67 lines
1.6 KiB
JavaScript

const Benchmark = require('benchmark');
const acorn = require("acorn");
const jsx = require("acorn-jsx");
const parser = acorn.Parser.extend(jsx());
const fs = require('fs');
const path = require('path');
const src = fs.readFileSync(path.join(process.argv[2], "input.js"), 'utf8');
const jsonStr = fs.readFileSync(path.join(process.argv[2], "output.json"), 'utf8');
{
parser.parse(src, {
ecmaVersion: 2020,
ranges: true,
allowHashBang: true,
sourceType: 'module'
})
}
const suite = new Benchmark.Suite;
suite
.add('acorn', () => {
parser.parse(src, {
ecmaVersion: 2020,
ranges: true,
allowHashBang: true,
sourceType: 'module'
})
})
.add({
name: 'acorn-real',
fn: (deferred) => {
fs.promises.readFile(path.join(process.argv[2], "input.js"), 'utf8')
.then((src) => {
parser.parse(src, {
ecmaVersion: 2020,
ranges: true,
allowHashBang: true,
sourceType: 'module'
});
deferred.resolve()
})
},
defer: true,
async: true,
queued: true
})
.add('json', () => {
JSON.parse(jsonStr)
})
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({
async: true
})