mirror of
https://github.com/swc-project/swc.git
synced 2024-12-21 04:32:01 +03:00
c2bbdbe9d6
swc_estree_compat: - Fix stack overflow related to object patterns. swc_webpack_}ast: - Implement AST reducer.
67 lines
1.6 KiB
JavaScript
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
|
|
})
|