@@ -55,10 +55,10 @@ for (const fixture of FIXTURES) {
5555
5656console . log ( "=== Real-World Source Map Benchmarks ===\n" ) ;
5757console . log ( "Libraries:" ) ;
58- console . log ( " @jridgewell/trace-mapping — de facto standard JS source map consumer" ) ;
59- console . log ( " source-map-js — Mozilla source-map fork (used by Vite, PostCSS)" ) ;
60- console . log ( " srcmap WASM — srcmap Rust core via WebAssembly" ) ;
61- console . log ( " srcmap NAPI — srcmap Rust core via N-API\n" ) ;
58+ console . log ( " @jridgewell/trace-mapping - de facto standard JS source map consumer" ) ;
59+ console . log ( " source-map-js - Mozilla source-map fork (used by Vite, PostCSS)" ) ;
60+ console . log ( " srcmap WASM - srcmap Rust core via WebAssembly" ) ;
61+ console . log ( " srcmap NAPI - srcmap Rust core via N-API\n" ) ;
6262
6363console . log ( "Source maps:" ) ;
6464for ( const m of maps ) {
@@ -142,13 +142,14 @@ for (const { name, json, size } of maps) {
142142 // Fewer iterations for large maps
143143 const iterations = size > 1024 * 1024 ? 50 : 200 ;
144144 const bench = createBench ( { warmupIterations : 10 , iterations } ) ;
145+ const prefix = `real_world_parse[${ name } ]` ;
145146
146147 bench
147- . add ( " trace-mapping" , ( ) => new TraceMap ( json ) )
148- . add ( " source-map-js" , ( ) => new SourceMapConsumer ( json ) )
149- . add ( " srcmap WASM" , ( ) => new SourceMap ( json ) )
150- . add ( " srcmap WASM ( fast)" , ( ) => new FastSourceMap ( json ) )
151- . add ( " srcmap NAPI" , ( ) => new NapiSourceMap ( json ) ) ;
148+ . add ( ` ${ prefix } trace-mapping` , ( ) => new TraceMap ( json ) )
149+ . add ( ` ${ prefix } source-map-js` , ( ) => new SourceMapConsumer ( json ) )
150+ . add ( ` ${ prefix } srcmap WASM` , ( ) => new SourceMap ( json ) )
151+ . add ( ` ${ prefix } srcmap WASM fast` , ( ) => new FastSourceMap ( json ) )
152+ . add ( ` ${ prefix } srcmap NAPI` , ( ) => new NapiSourceMap ( json ) ) ;
152153
153154 await bench . run ( ) ;
154155
@@ -166,7 +167,7 @@ for (const { name, json, size } of maps) {
166167
167168console . log ( "\n--- Single Lookup ---\n" ) ;
168169
169- for ( const { name, json } of maps ) {
170+ for ( const { name, json, size } of maps ) {
170171 console . log ( `### ${ name } \n` ) ;
171172
172173 const trace = new TraceMap ( json ) ;
@@ -177,17 +178,26 @@ for (const { name, json } of maps) {
177178 // Pick a lookup position roughly in the middle of the map
178179 const midLine = Math . floor ( wasm . lineCount / 2 ) ;
179180
180- const bench = createBench ( { warmupIterations : 500 , iterations : 5000 } ) ;
181+ const isLargeMap = size > 1024 * 1024 ;
182+ const bench = createBench ( {
183+ warmupIterations : isLargeMap ? 50 : 500 ,
184+ iterations : isLargeMap ? 500 : 5000 ,
185+ } ) ;
186+ const prefix = `real_world_lookup_single[${ name } ]` ;
181187
182188 bench
183- . add ( "trace-mapping" , ( ) => originalPositionFor ( trace , { line : midLine + 1 , column : 20 } ) )
184- . add ( "source-map-js" , ( ) => smjs . originalPositionFor ( { line : midLine + 1 , column : 20 } ) )
185- . add ( "srcmap WASM" , ( ) => wasm . originalPositionFor ( midLine , 20 ) )
186- . add ( "srcmap WASM (flat)" , ( ) => wasm . originalPositionFlat ( midLine , 20 ) )
187- . add ( "srcmap WASM (buf)" , ( ) => {
189+ . add ( `${ prefix } trace-mapping` , ( ) =>
190+ originalPositionFor ( trace , { line : midLine + 1 , column : 20 } ) ,
191+ )
192+ . add ( `${ prefix } source-map-js` , ( ) =>
193+ smjs . originalPositionFor ( { line : midLine + 1 , column : 20 } ) ,
194+ )
195+ . add ( `${ prefix } srcmap WASM` , ( ) => wasm . originalPositionFor ( midLine , 20 ) )
196+ . add ( `${ prefix } srcmap WASM flat` , ( ) => wasm . originalPositionFlat ( midLine , 20 ) )
197+ . add ( `${ prefix } srcmap WASM buf` , ( ) => {
188198 wasm . originalPositionBuf ( midLine , 20 ) ;
189199 } )
190- . add ( " srcmap NAPI" , ( ) => napi . originalPositionFor ( midLine , 20 ) ) ;
200+ . add ( ` ${ prefix } srcmap NAPI` , ( ) => napi . originalPositionFor ( midLine , 20 ) ) ;
191201
192202 await bench . run ( ) ;
193203
@@ -205,7 +215,7 @@ for (const { name, json } of maps) {
205215
206216console . log ( "\n--- 1000x Lookup ---\n" ) ;
207217
208- for ( const { name, json } of maps ) {
218+ for ( const { name, json, size } of maps ) {
209219 console . log ( `### ${ name } \n` ) ;
210220
211221 const trace = new TraceMap ( json ) ;
@@ -225,23 +235,28 @@ for (const { name, json } of maps) {
225235 }
226236 const posArray = new Int32Array ( flatPositions ) ;
227237
228- const bench = createBench ( { warmupIterations : 20 , iterations : 200 } ) ;
238+ const isLargeMap = size > 1024 * 1024 ;
239+ const bench = createBench ( {
240+ warmupIterations : isLargeMap ? 5 : 20 ,
241+ iterations : isLargeMap ? 50 : 200 ,
242+ } ) ;
243+ const prefix = `real_world_lookup_1000x[${ name } ]` ;
229244
230245 bench
231- . add ( " trace-mapping" , ( ) => {
246+ . add ( ` ${ prefix } trace-mapping` , ( ) => {
232247 for ( const { line, column } of lookups )
233248 originalPositionFor ( trace , { line : line + 1 , column } ) ;
234249 } )
235- . add ( " source-map-js" , ( ) => {
250+ . add ( ` ${ prefix } source-map-js` , ( ) => {
236251 for ( const { line, column } of lookups ) smjs . originalPositionFor ( { line : line + 1 , column } ) ;
237252 } )
238- . add ( " srcmap WASM ( individual)" , ( ) => {
253+ . add ( ` ${ prefix } srcmap WASM individual` , ( ) => {
239254 for ( const { line, column } of lookups ) wasm . originalPositionFor ( line , column ) ;
240255 } )
241- . add ( " srcmap WASM ( batch)" , ( ) => {
256+ . add ( ` ${ prefix } srcmap WASM batch` , ( ) => {
242257 wasm . originalPositionsFor ( posArray ) ;
243258 } )
244- . add ( " srcmap NAPI ( batch)" , ( ) => {
259+ . add ( ` ${ prefix } srcmap NAPI batch` , ( ) => {
245260 napi . originalPositionsFor ( flatPositions ) ;
246261 } ) ;
247262
0 commit comments