11import { createBench , latencyMeanMs , latencyP99Ms , throughputHz } from "./codspeed.mjs" ;
2+ import { createDeterministicLookups , setFailureExitCode } from "./workload.mjs" ;
23import { readFileSync , existsSync } from "node:fs" ;
34import { dirname , join } from "node:path" ;
45import { fileURLToPath } from "node:url" ;
@@ -13,6 +14,9 @@ import { SourceMap as NapiSourceMap } from "../packages/sourcemap/index.js";
1314
1415const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
1516const fixturesDir = join ( __dirname , "fixtures" ) ;
17+ const LOOKUP_COUNT = 1_000 ;
18+ const LOOKUP_MAX_COLUMN = 200 ;
19+ const LOOKUP_SEED = 0x5eed1234 ;
1620
1721// ── Load fixtures ────────────────────────────────────────────────
1822
@@ -80,6 +84,8 @@ const normalizePath = (s) => s?.replace(/\/\.\//g, "/") ?? null;
8084
8185console . log ( "\n--- Correctness Check ---\n" ) ;
8286
87+ const correctnessResults = [ ] ;
88+
8389for ( const { name, json } of maps ) {
8490 const trace = new TraceMap ( json ) ;
8591 const wasm = new SourceMap ( json ) ;
@@ -130,8 +136,11 @@ for (const { name, json } of maps) {
130136 console . log (
131137 ` ${ name } : WASM ${ wasmPass ? "PASS" : "FAIL" } , NAPI ${ napiPass ? "PASS" : "FAIL" } (${ checked } lookups)` ,
132138 ) ;
139+ correctnessResults . push ( { wasmPass, napiPass } ) ;
133140}
134141
142+ setFailureExitCode ( correctnessResults ) ;
143+
135144// ── Parse benchmarks ─────────────────────────────────────────────
136145
137146console . log ( "\n--- Parse ---\n" ) ;
@@ -224,15 +233,8 @@ for (const { name, json, size } of maps) {
224233 const napi = new NapiSourceMap ( json ) ;
225234 const maxLine = wasm . lineCount ;
226235
227- const lookups = [ ] ;
228- const flatPositions = [ ] ;
229-
230- for ( let i = 0 ; i < 1000 ; i ++ ) {
231- const line = Math . floor ( Math . random ( ) * maxLine ) ;
232- const column = Math . floor ( Math . random ( ) * 200 ) ;
233- lookups . push ( { line, column } ) ;
234- flatPositions . push ( line , column ) ;
235- }
236+ const lookups = createDeterministicLookups ( LOOKUP_COUNT , maxLine , LOOKUP_MAX_COLUMN , LOOKUP_SEED ) ;
237+ const flatPositions = lookups . flatMap ( ( { line, column } ) => [ line , column ] ) ;
236238 const posArray = new Int32Array ( flatPositions ) ;
237239
238240 const isLargeMap = size > 1024 * 1024 ;
0 commit comments