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
Raymond Chen's Find the index of the smallest element in a JavaScript array
function makeRandomArray(length) {
var a = new Array(length);
for (var i = 0; i < a.length; i++) {
a[i] = Math.random();
}
return a;
}
var array100k = makeRandomArray(100 * 1000);
var array200k = makeRandomArray(200 * 1000);
var array250k = makeRandomArray(250 * 1000);
function indexOfSmallestManual(a) {
var lowest = 0;
var l=999999;
for (var i = 1; i < a.length; i++) {
if (a[i] < l) { lowest = i; l = a[i]; }
}
return lowest;
}
function indexOfSmallestReduce(a) {
return a.reduce(function(lowest, next, index) {
return next < a[lowest] ? index : lowest; },
0);
}
function indexOfSmallestMinIndexOf(a) {
return a.indexOf(Math.min.apply(Math, a));
}
Ready to run.
Test | Ops/sec | |
---|---|---|
manual 100k |
| ready |
manual 200k |
| ready |
manual 250k |
| ready |
reduce 100k |
| ready |
reduce 200k |
| ready |
reduce 250k |
| ready |
min/indexOf 100k |
| ready |
min/indexOf 200k |
| ready |
min/indexOf 250k |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.