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
Looking for elements at the very start of the array gives a false impression, see how the picture changes if they elements are at the end of the array.
But how long does it take to build and object lookup table?
var obj = {},
arr = [],
count = 0;
for (var i = 0; i < 1000; i++) {
arr.push(i);
obj[i] = 1;
}
function in_array(needle, haystack) {
for (var i = 0, maxi = haystack.length; i < maxi; ++i) {
if (haystack[i] == needle) {
return true;
}
}
return false;
}
function include(needle, haystack) {
return (haystack.indexOf(needle) != -1);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
find in array (1) |
| ready |
find in array (500) |
| ready |
find in array (999) |
| ready |
find in obj (1) |
| ready |
find in obj (500) |
| ready |
find in obj (999) |
| ready |
indexOf in arr(1) |
| ready |
indexOf in arr(500) |
| ready |
indexOf in arr(999) |
| ready |
build lookup index |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.