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
splice is notoriously slow. wanted to see if rebuilding an array would be faster or slower than splice.
var newStrArr_splice,
newObjArr_splice,
newStrArr_rebuild,
newObjArr_rebuild,
arrayLength = 100000,
strArr = new Array(arrayLength),
objArr = new Array(arrayLength);
for (var i = arrayLength - 1; i >= 0; i--) {
var objTemplate = {something: 'stringy', id: i, attributes: {}},
strTemplate = 'stringy-' + i,
newObj = objTemplate;
strArr[i] = strTemplate;
objArr[i] = objTemplate;
}
var randPos = Math.round(Math.random()* (arrayLength / 2)) + (arrayLength / 4);
function rebuildArray(array, index, excludeTo) {
var newArr = [];
for (var i = array.length - 1; i >= 0; i--) {
if (i >= index + excludeTo) {
newArr.push(array[i]);
}
if (i < index) {
newArr.push(array[i]);
}
}
return array.reverse();
}
window.console.log(newStrArr_splice);
window.console.log(newObjArr_splice);
window.console.log(newStrArr_rebuild);
window.console.log(newObjArr_rebuild);
Ready to run.
Test | Ops/sec | |
---|---|---|
splice string array |
| ready |
splice object array |
| ready |
rebuild string array |
| ready |
rebuild object array |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.