bench .add('native', () => foo.map(bar)) .add('map-arr', () => curr(foo, bar)) .add('arr-map', () => arrMap(foo, bar)) .add('array-map', () => arrayMap(foo, bar)) .add('fast.map', () => fast(foo, bar)) .on('cycle', e => console.log(String(e.target))) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').map('name')); const tbl = new Table({ head: ['Name', 'Mean time', 'Ops/sec', 'Diff'] }); let prev, diff; bench.forEach(el => { if (prev) { diff = ((el.hz - prev) * 100 / prev).toFixed(2) + '% faster'; } else { diff = 'N/A' } prev = el.hz; tbl.push([el.name, el.stats.mean, el.hz.toLocaleString(), diff]) }); console.log(tbl.toString()); }) .run();
suite.forEach(benchmark => { benchmark.on("start", event => { if (suite.aborted) return; displayResultMessage( benchmark.name, "<em>Running...</em>", "highlighted-result" ); displayStatusMessage(`Running iteration 1 of ${benchmark.name}...`); }); benchmark.on("cycle", event => { if (suite.aborted) return; const iteration = benchmark.stats.sample.length + 1; displayStatusMessage( `Running iteration ${iteration} of ${benchmark.name}...` ); }); benchmark.on("complete", event => { if (suite.aborted) return; displayResultMessage( benchmark.name, `${benchmark.hz.toFixed(2)}`, "result" ); const iterations = benchmark.stats.sample.length; displayStatusMessage( `Ran ${iterations} iterations of ${benchmark.name}...` ); }); });
suite.forEach(benchmark => benchmarks.push(benchmark));