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.
<script>
// setup `arr` array ('small')
var arr = ['1', true, false, "", void 0, null, 2, 18.5936];
// testing for having deleted keys in array
delete(arr[3]);
// seed `arr_keys` hash
var arr_keys = {};
for (var i = 0; i < arr.length; i++) {
arr.hasOwnProperty(i) && (arr_keys[i] = 0);
}
// setup `arr2` array ('medium')
var arr2 = arr.slice(0);
for (var j = 0; j < 500; j++) {
arr2.push(Math.round(Math.random()));
}
// seed `arr2_keys` hash
var arr2_keys = {};
for (j = 0; j < arr2.length; j++) {
arr2.hasOwnProperty(j) && (arr2_keys[j] = 0);
}
// setup `arr3` array ('big')
var arr3 = arr2.slice(0);
for (var m = 0; m < 5000; m++) {
arr3.push(Math.round(Math.random()));
}
// seed `arr3_keys` hash
var arr3_keys = {};
for (m = 0; m < arr3.length; m++) {
arr3.hasOwnProperty(m) && (arr3_keys[m] = 0);
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
big array: for-loop |
| ready |
big array: for-in-loop |
| ready |
big array: native forEach |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.