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
var values = [41, 73, 98, 62, 85, 51, 28, 89, 20];
var minReduce = function(arr) {
return arr.reduce(function(p, v) {
return (p < v ? p : v);
});
};
var maxReduce = function(arr) {
return arr.reduce(function(p, v) {
return (p > v ? p : v);
});
};
var minMath = function(arr) {
return Math.min.apply(null, arr);
};
var maxMath = function(arr) {
return Math.max.apply(null, arr);
};
var minLoop = function(arr) {
var len = arr.length,
min = Infinity;
while (len--) {
if (arr[len] < min) {
min = arr[len];
}
}
return min;
};
var maxLoop = function(arr) {
var len = arr.length,
max = -Infinity;
while (len--) {
if (arr[len] > max) {
max = arr[len];
}
}
return max;
};
var minLoopFor = function(arr) {
var min = Infinity;
for (var i = arr.length-1; i>=0; i--) {
if (arr[i] < min) {
min = arr[i];
}
}
return min;
};
var maxLoopFor = function(arr) {
var max = -Infinity;
for (var i = arr.length-1; i>=0; i--) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
};
var minLoopUp = function(arr) {
var min = Infinity;
for (var i = 0; i < arr.length; i++) {
if (arr[i] < min) {
min = arr[i];
}
}
return min;
};
var maxLoopUp = function(arr) {
var max = -Infinity;
for (var i = 0; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
};
var minLoopIn = function(arr) {
var min = Infinity;
for (var i in arr) {
if (arr[i] < min) {
min = arr[i];
}
}
return min;
};
var maxLoopIn = function(arr) {
var max = -Infinity;
for (var i in arr) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
};
var minLoopFast = function(arr) {
var min = arr[0];
for (var i = 1, n = arr.length; i < n; i++) {
if (arr[i] < min) {
min = arr[i];
}
}
return min;
};
var maxLoopFast = function(arr) {
var max = arr[0];
for (var i = 1, n = arr.length; i < n; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
};
var minLoopIdx = function(arr) {
var min = 0;
for (var i = 1, n = arr.length; i < n; i++) {
if (arr[i] < arr[min]) {
min = i;
}
}
return arr[min];
};
var maxLoopIdx = function(arr) {
var max = 0;
for (var i = 1, n = arr.length; i < n; i++) {
if (arr[i] > arr[max]) {
max = i;
}
}
return arr[max];
};
var minLoopMath = function(arr) {
var min = arr[0];
for (var i = 1, n = arr.length; i < n; i++) {
min = Math.min(arr[i], min);
}
return min;
};
var maxLoopMath = function(arr) {
var max = arr[0];
for (var i = 1, n = arr.length; i < n; i++) {
max = Math.max(arr[i], max);
}
return max;
};
var minmaxLoop = function(arr) {
var min = arr[0];
var max = arr[0];
for (var i = 1, n = arr.length; i < n; i++) {
if (arr[i] > max) {
max = arr[i];
}
if (arr[i] < min) {
min = arr[i];
}
}
return [min, max];
};
Ready to run.
Test | Ops/sec | |
---|---|---|
Reduce |
| ready |
Math |
| ready |
Loop |
| ready |
LoopFor |
| ready |
LoopUp |
| ready |
LoopIn |
| ready |
LoopFast |
| ready |
LoopIdx |
| ready |
LoopMath |
| ready |
LoopMinMax |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.