MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 36 lines 947 B view raw
1function runBench(label, fn, options) { 2 const warmup = options && options.warmup ? options.warmup : 5; 3 const samples = options && options.samples ? options.samples : 10; 4 5 for (let i = 0; i < warmup; i++) fn(); 6 7 let min = Infinity; 8 let max = -Infinity; 9 let total = 0; 10 let last = 0; 11 12 for (let i = 0; i < samples; i++) { 13 const start = performance.now(); 14 last = fn(); 15 const elapsed = performance.now() - start; 16 if (elapsed < min) min = elapsed; 17 if (elapsed > max) max = elapsed; 18 total += elapsed; 19 } 20 21 console.log(label); 22 console.log(` result: ${last}`); 23 console.log(` mean: ${ (total / samples).toFixed(3) } ms`); 24 console.log(` min: ${ min.toFixed(3) } ms`); 25 console.log(` max: ${ max.toFixed(3) } ms`); 26} 27 28const arr = Array(1024); 29 30runBench("sparse includes(undefined)", () => { 31 let hits = 0; 32 for (let r = 0; r < 50000; r++) { 33 if (arr.includes(undefined)) hits++; 34 } 35 return hits; 36});