Skip to content

Commit 21c2a40

Browse files
authored
Merge pull request #39 from unassert-js/benchmark-commits
perf: Add Benchmark Suite to run benchmark continuously
2 parents 77ebec0 + d7da317 commit 21c2a40

File tree

4 files changed

+248
-0
lines changed

4 files changed

+248
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
* Restructured codebase
1010
* [Migrate codebase to ESM and provide CJS/ESM dual package](https://github.com/unassert-js/unassert/pull/29)
1111
* [Replace default exported `unassert` with named exported `unassertAst`](https://github.com/unassert-js/unassert/pull/27)
12+
13+
* Performance improvement
1214
* [Replace AST matcher with simpler and robust logic](https://github.com/unassert-js/unassert/pull/25)
15+
* [Add Benchmark Suite to run benchmark continuously](https://github.com/unassert-js/unassert/pull/39)
16+
* v2.0.0 is 20 times faster than v1.6.0
1317

1418
* Newly supported syntaxes and features
1519
* [Support strict assertion mode newly exposed as 'node:assert/strict'](https://github.com/unassert-js/unassert/pull/31)

bench.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { runBenchmark } from '@twada/benchmark-commits';
2+
import { parse } from 'acorn';
3+
import { readFileSync } from 'node:fs';
4+
import { join, dirname } from 'node:path';
5+
import { fileURLToPath, pathToFileURL } from 'node:url';
6+
import assert from 'node:assert/strict';
7+
const __dirname = dirname(fileURLToPath(import.meta.url));
8+
const targetCode = readFileSync(join(__dirname, 'node_modules', 'rimraf', 'rimraf.js'));
9+
10+
const commits = [
11+
'v1.6.0',
12+
'master'
13+
];
14+
15+
runBenchmark(commits, async ({ suite, spec, dir }) => {
16+
let unassertAst;
17+
if (spec.git === 'v1.6.0') {
18+
unassertAst = (await import(pathToFileURL(`${dir}/index.js`))).default;
19+
} else if (spec.git === 'master') {
20+
unassertAst = (await import(pathToFileURL(`${dir}/src/index.mjs`))).unassertAst;
21+
} else {
22+
assert.fail('cannot be here');
23+
}
24+
return () => {
25+
const ast = parse(targetCode, { ecmaVersion: '2022' });
26+
const modifiedAst = unassertAst(ast);
27+
assert(modifiedAst);
28+
};
29+
}).then((suite) => {
30+
console.log('FINISHED');
31+
});

package-lock.json

Lines changed: 212 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"estraverse": "^5.0.0"
1919
},
2020
"devDependencies": {
21+
"@twada/benchmark-commits": "^0.1.0",
2122
"acorn": "^8.0.0",
2223
"escodegen": "^2.0.0",
2324
"mocha": "^10.0.0",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy