| 1 |
/* |
| 2 |
* reduce-plan-deep |
| 3 |
* |
| 4 |
* Deeply nested path plans exercise the parent-chain walk in reducePlan's |
| 5 |
* tree-building pass (each leaf bubbles its entry count up an arbitrarily |
| 6 |
* long ancestor list) and the subtree-deactivation walk during reduction |
| 7 |
* (merging near the root has to mark every descendant inactive). |
| 8 |
* |
| 9 |
* `depth=30, leaves=3` approximates a monorepo with a handful of files at |
| 10 |
* every level; `depth=80, leaves=2` is a synthetic worst case with a long |
| 11 |
* spine and very few siblings per rung. |
| 12 |
*/ |
| 13 |
|
| 14 |
import reducePlan from "../../../lib/reducePlan.js"; |
| 15 |
|
| 16 |
const ROOT = process.platform === "win32" ? "C:\\root" : "/root"; |
| 17 |
const SEP = process.platform === "win32" ? "\\" : "/"; |
| 18 |
|
| 19 |
/** |
| 20 |
* @param {number} depth directory depth |
| 21 |
* @param {number} leaves leaves per level |
| 22 |
* @returns {Map<string, string>} plan |
| 23 |
*/ |
| 24 |
const buildDeepPlan = (depth, leaves) => { |
| 25 |
const plan = new Map(); |
| 26 |
let i = 0; |
| 27 |
const walk = (prefix, level) => { |
| 28 |
for (let l = 0; l < leaves; l++) { |
| 29 |
plan.set(`${prefix}${SEP}file${i}`, `v${i++}`); |
| 30 |
} |
| 31 |
if (level < depth) walk(`${prefix}${SEP}sub${level}`, level + 1); |
| 32 |
}; |
| 33 |
walk(ROOT, 0); |
| 34 |
return plan; |
| 35 |
}; |
| 36 |
|
| 37 |
const deepPlan = buildDeepPlan(30, 3); |
| 38 |
const veryDeepPlan = buildDeepPlan(80, 2); |
| 39 |
|
| 40 |
/** |
| 41 |
* @param {import("tinybench").Bench} bench bench |
| 42 |
*/ |
| 43 |
export default function register(bench) { |
| 44 |
bench.add("reduce-plan-deep: depth=30, leaves=3, limit=20", () => { |
| 45 |
reducePlan(deepPlan, 20); |
| 46 |
}); |
| 47 |
bench.add("reduce-plan-deep: depth=80, leaves=2, limit=40", () => { |
| 48 |
reducePlan(veryDeepPlan, 40); |
| 49 |
}); |
| 50 |
} |