Skip to content

Commit 40422e8

Browse files
committedOct 30, 2024
Merge branch 'gh-pages' of github.com:jviereck/regjsparser into gh-pages
2 parents ac51d2b + 2fbb816 commit 40422e8

File tree

4 files changed

+441
-259
lines changed

4 files changed

+441
-259
lines changed
 

‎package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
},
1616
"scripts": {
1717
"lint": "eslint --max-warnings 0 .",
18-
"test": "run-p test:* && npm run lint",
18+
"test": "run-p test:* lint",
1919
"test:src": "node test/index.js",
20-
"test:types": "tsc test/types.ts --noEmit"
20+
"test:types": "tsc test/types.ts --noEmit",
21+
"bench:baseline": "node ./tools/bench/index.mjs baseline",
22+
"bench:current": "node ./tools/bench/index.mjs current",
23+
"bench": "run-s bench:*"
2124
},
2225
"files": [
2326
"bin/",
@@ -36,6 +39,8 @@
3639
"globals": "^15.9.0",
3740
"npm-run-all": "^4.1.5",
3841
"regenerate": "~1.0.1",
42+
"regjsparser": "^0.11.2",
43+
"tinybench": "^2.9.0",
3944
"typescript": "^4.5.2"
4045
}
4146
}

‎parser.js

+371-257
Large diffs are not rendered by default.

‎tools/bench/index.mjs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Bench } from "tinybench";
2+
3+
import * as parserCurrent from "../../parser.js";
4+
import * as parserBaseline from "regjsparser";
5+
import { samples } from "./samples.mjs";
6+
7+
const parseCurrent = parserCurrent.default.parse;
8+
const parseBaseline = parserBaseline.default.parse;
9+
10+
const parse = process.argv[2] === "current" ? parseCurrent : parseBaseline;
11+
const bench = new Bench({ name: "benchmark between baseline and current", time: 500 });
12+
13+
for (const [title, sample] of Object.entries(samples)) {
14+
const regex = sample.slice(1, sample.lastIndexOf("/"));
15+
const flags = sample.slice(sample.lastIndexOf("/"));
16+
17+
bench.add("parse " + process.argv[2] + " " + title, () => {
18+
parse(regex, flags, {
19+
modifiers: true,
20+
unicodeSet: true,
21+
unicodePropertyEscape: true,
22+
namedGroups: true,
23+
lookbehind: true,
24+
});
25+
});
26+
}
27+
28+
await bench.run();
29+
30+
console.table(bench.table());

‎tools/bench/samples.mjs

+33
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.