@@ -4,8 +4,10 @@ const RUNS = 3e4
44const src = c => `1 + (a * b / c % d) - 2.0 + -3e-3 * +4.4e4 / f.g[0] - i.j(+k == 1)(${ c } )`
55const subscriptUrl = new URL ( '../subscript.js' , import . meta. url ) . href
66const justinUrl = new URL ( '../justin.js' , import . meta. url ) . href
7+ // Browser uses CDN, Node uses npm package
8+ const jsepUrl = typeof process !== 'undefined' ? 'jsep' : 'https://esm.sh/jsep'
79
8- test . fork ( 'perf: expr < jsep' , { data : { RUNS , src, subscriptUrl} } , async ( { ok } , { RUNS , src, subscriptUrl} ) => {
10+ test . fork ( 'perf: expr < jsep' , { data : { RUNS , src, subscriptUrl, jsepUrl } } , async ( { ok } , { RUNS , src, subscriptUrl, jsepUrl } ) => {
911 const bench = ( fn ) => {
1012 let best = Infinity
1113 for ( let r = 0 ; r < 3 ; r ++ ) {
@@ -17,7 +19,7 @@ test.fork('perf: expr < jsep', {data: {RUNS, src, subscriptUrl}}, async ({ ok },
1719 }
1820
1921 const { parse } = await import ( subscriptUrl )
20- const jsep = ( await import ( 'jsep' ) ) . default
22+ const jsep = ( await import ( jsepUrl ) ) . default
2123
2224 for ( let w = 0 ; w < RUNS ; w ++ ) { parse ( src ( w ) ) ; jsep ( src ( w ) ) }
2325
@@ -27,7 +29,7 @@ test.fork('perf: expr < jsep', {data: {RUNS, src, subscriptUrl}}, async ({ ok },
2729 ok ( time < baseline , `expr (${ time . toFixed ( 0 ) } ms) should be < jsep (${ baseline . toFixed ( 0 ) } ms)` )
2830} )
2931
30- test . fork ( 'perf: justin <= jsep' , { data : { RUNS , src, justinUrl} } , async ( { ok } , { RUNS , src, justinUrl} ) => {
32+ test . fork ( 'perf: justin <= jsep' , { data : { RUNS , src, justinUrl, jsepUrl } } , async ( { ok } , { RUNS , src, justinUrl, jsepUrl } ) => {
3133 const bench = ( fn ) => {
3234 let best = Infinity
3335 for ( let r = 0 ; r < 3 ; r ++ ) {
@@ -39,7 +41,7 @@ test.fork('perf: justin <= jsep', {data: {RUNS, src, justinUrl}}, async ({ ok },
3941 }
4042
4143 const { parse } = await import ( justinUrl )
42- const jsep = ( await import ( 'jsep' ) ) . default
44+ const jsep = ( await import ( jsepUrl ) ) . default
4345
4446 for ( let w = 0 ; w < RUNS ; w ++ ) { parse ( src ( w ) ) ; jsep ( src ( w ) ) }
4547
0 commit comments