Debian Codegraph @

benchmark/babel-traverse/enter-visitor-context-change/bench.mjs

raw symbols SCIP
1 import Benchmark from "benchmark";
2 import baseline from "@babel-baseline/traverse";
3 import current from "@babel/traverse";
4 import parser from "@babel-baseline/parser";
5 import { report } from "../../util.mjs";
6
7 const suite = new Benchmark.Suite();
8 function createInput(length) {
9 return parser.parse(";".repeat(length));
10 }
11 function benchCases(name, implementation, options) {
12 for (const length of [256, 512, 1024, 2048]) {
13 const input = createInput(length);
14 suite.add(`${name} ${length} empty statements`, () => {
15 implementation(input, options);
16 });
17 }
18 }
19
20 benchCases("baseline", baseline.default, {
21 enter() {},
22 });
23 benchCases("baseline mutating context", baseline.default, {
24 enter(path) {
25 path.context = undefined;
26 },
27 });
28 benchCases("current", current.default, {
29 enter() {},
30 });
31 benchCases("current mutating context", current.default, {
32 enter(path) {
33 path.context = undefined;
34 },
35 });
36
37 suite.on("cycle", report).run();