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
Testing the speed of iterating various sized arrays with straight for-loop or with a for-in-loop over its keys or using the native Array.forEach() API.
The difference with other tests is that these arrays contain 'gaps' i.e. do not have all their array slots in the range 0..array.length filled with values.
Note: all arrays have the same array.length!
// setup `arr` array ('small/tiny')
var arr = ['1', true, false, "", undefined, "", void 0, null, 2, 18.5936];
// testing for having deleted keys in array
delete(arr[3]);
// setup `arr2` array ('medium gap')
var arr2 = arr.slice(0);
var j = 1;
arr2[arr2.length + j] = Math.round(Math.random());
// setup `arr3` array ('big gap')
var arr3 = arr2.slice(0);
var k = 5000;
arr3[arr3.length + k] = Math.round(Math.random());
// pad the arrays to length of arr3
var len = arr3.length;
for (var i = arr.length; i < len; i++) {
if ((i % 10) === 3) continue; // tiny gaps
arr[i] = Math.round(Math.random());
}
for (var i = arr2.length; i < len; i++) {
if ((i % (j + 10)) < (j - 10)) continue; // medium gaps
arr2[i] = Math.round(Math.random());
}
arr[len] = Math.round(Math.random());
arr2[len] = Math.round(Math.random());
arr3[len] = Math.round(Math.random());
// and we're testing hammer hammer spam spam
Ready to run.
Test | Ops/sec | |
---|---|---|
big gap array: for-loop |
| ready |
big gap array: for-in-loop |
| ready |
big gap array: native forEach |
| ready |
small gap array: for-loop |
| ready |
small gap array: for-in-loop |
| ready |
small gap array: forEach |
| ready |
tiny gap array: for-loop |
| ready |
tiny gap array: for-in-loop |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.