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 speed of a standard for loop vs. Array.indexOf vs. inverse for loop vs. while loop vs. for with cached length.
Checking for 5000 in a 10000 index array for equal opportunity inverse.
Added a test case suitable for just checking a presence of some value in a set of values when there is no need to keep array type.
<script>
var ar = [],
ob = {};
for (var i = 0; i < 10000; i++){
/*
The idea is to flip keys with values to make the search
faster using in, thus we need to make values differ from keys
*/
var v = i + Math.random() + ""; // And let's make them strings
ar.push(v);
ob[v] = i;
var ref = ar[5000];
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
For loop |
| ready |
indexOf |
| ready |
inverse for-loop |
| ready |
while loop |
| ready |
For loop cached |
| ready |
In-check |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.