jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
slice with spread vs map
/**
* @param {number} numItems
*/
function makeArray(numItems) {
const array = [];
for (let i = 0; i < numItems; i++) {
array.push({ title: `title${i}`, description: `description${i}` });
}
return array;
}
/**
* @param {number} index
* @param {any} updatedItem
* @param {any[]} array
*/
function updateArrayWithMap(index, updatedItem, array) {
const newModules = array.map((module, i) => {
if (i === index) {
return updatedItem;
}
return module;
});
return newModules;
}
/**
* @param {number} index
* @param {any} updatedItem
* @param {any[]} array
*/
function updateArrayWithSlice(index, updatedItem, array) {
const newModules = [...array.slice(0, index), updatedItem, ...array.slice(index + 1)];
return newModules;
}
const array10 = makeArray(10)
const array100 = makeArray(100)
const array1000 = makeArray(1000)
const array10000 = makeArray(10000)
const array100000 = makeArray(100000)
Ready to run.
Test | Ops/sec | |
---|---|---|
With Map with 10 items |
| ready |
With Slice with 10 items |
| ready |
With Map with 100 items |
| ready |
With Slice with 100 items |
| ready |
With Map with 1000 items |
| ready |
With Slice with 1000 items |
| ready |
With Map with 10000 items |
| ready |
With Slice with 10000 items |
| ready |
With Map with 100000 items |
| ready |
With Slice with 100000 items |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.