-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbench.mjs
31 lines (29 loc) · 1019 Bytes
/
bench.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { runBenchmark } from '@twada/benchmark-commits';
import { parse } from 'acorn';
import { readFileSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import assert from 'node:assert/strict';
const __dirname = dirname(fileURLToPath(import.meta.url));
const targetCode = readFileSync(join(__dirname, 'node_modules', 'rimraf', 'rimraf.js'));
const commits = [
'v1.6.0',
'master'
];
runBenchmark(commits, async ({ suite, spec, dir }) => {
let unassertAst;
if (spec.git === 'v1.6.0') {
unassertAst = (await import(pathToFileURL(`${dir}/index.js`))).default;
} else if (spec.git === 'master') {
unassertAst = (await import(pathToFileURL(`${dir}/src/index.mjs`))).unassertAst;
} else {
assert.fail('cannot be here');
}
return () => {
const ast = parse(targetCode, { ecmaVersion: '2022' });
const modifiedAst = unassertAst(ast);
assert(modifiedAst);
};
}).then((suite) => {
console.log('FINISHED');
});