mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Implement "node:module"'s findSourceMap and SourceMap class (#20863)
Co-authored-by: Claude <claude@anthropic.ai> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
28
bench/snippets/source-map.js
Normal file
28
bench/snippets/source-map.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import { SourceMap } from "node:module";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { bench, run } from "../runner.mjs";
|
||||
const json = JSON.parse(readFileSync(process.argv.at(-1), "utf-8"));
|
||||
|
||||
bench("new SourceMap(json)", () => {
|
||||
return new SourceMap(json);
|
||||
});
|
||||
|
||||
const map = new SourceMap(json);
|
||||
|
||||
const toRotate = [];
|
||||
for (let j = 0; j < 10000; j++) {
|
||||
if (map.findEntry(0, j).generatedColumn) {
|
||||
toRotate.push(j);
|
||||
if (toRotate.length > 5) break;
|
||||
}
|
||||
}
|
||||
let i = 0;
|
||||
bench("findEntry (match)", () => {
|
||||
return map.findEntry(0, toRotate[i++ % 3]).generatedColumn;
|
||||
});
|
||||
|
||||
bench("findEntry (no match)", () => {
|
||||
return map.findEntry(0, 9999).generatedColumn;
|
||||
});
|
||||
|
||||
await run();
|
||||
Reference in New Issue
Block a user