Test name | Executions per second |
---|---|
Control (for push) | 242991.2 Ops/sec |
Concat | 158066.1 Ops/sec |
Spread | 85451.8 Ops/sec |
Flat | 339913.8 Ops/sec |
window.top.tests = {control:[], concat:[], spread:[], flat: []};
window.test = (new Array(10)).fill(null);
window.arrays = (new Array(10)).fill(window.test);
window.cutoff = 5000;
window.top.tests.control = window.arrays.reduce((acc, arr) => {
acc.push(arr);
return acc;
}, []);
if (window.top.tests.control.length > window.cutoff) { window.top.tests.control = []; console.log('reset control'); }
window.top.tests.concat = window.arrays.reduce((acc, arr) => acc.concat(arr), []);
if (window.top.tests.concat.length > window.cutoff) { window.top.tests.concat = []; console.log('reset concat'); }
window.top.tests.spread = window.arrays.reduce((acc, arr) => [acc, arr], []);
if (window.top.tests.spread.length > window.cutoff) { window.top.tests.spread = []; console.log('reset spread'); }
window.top.tests.flat = window.arrays.flat();
if (window.top.tests.flat.length > window.cutoff) { window.top.tests.flat = []; console.log('reset flat'); }