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 some higher-order functions against their native counterparts. These are obviously not ECMAScript compliant. More info here.
<script>
/**
* Map a function over an Array (or Array-like object)
* @param {function(*): *} f
* @param {*} xs
* @return {Array}
*/
function map(f, xs) {
var length = xs.length;
var ys = [];
var i = 0;
while (i < length) {
ys[i] = f(xs[i++]);
}
return ys;
}
/**
* Filter an Array (or Array-like object)
* @param {function(*):boolean} p
* @param {*} xs
* @return {Array}
*/
function filter(p, xs) {
var length = xs.length;
var ys = [];
var i = 0;
var j = 0;
while (j < length) {
if (true === p(xs[j])) {
ys[i++] = xs[j];
}
++j;
}
return ys;
}
/**
* Fold an array from the left
* @param {function(*, *):*} f Combining function
* @param {*} z Initial value
* @param {*} xs
* @return {*}
*/
function foldl(f, z, xs) {
var length = xs.length;
var i = 0;
while (i < length) {
z = f(z, xs[i++]);
}
return z;
}
/**
* Fold an array from the right
* @param {function(...):*} f Combining function
* @param {*} z Initial value
* @param {*} xs An Array-like object
* @return {*}
*/
function foldr(f, z, xs) {
var i = xs.length;
while (i--) {
z = f(xs[i], z);
}
return z;
}
// Some test data/functions
var numbers = [0,1,2,3,4,5,6,7,8,9];
var strings = ["0","1","2","3","4","5","6","7","8","9"];
function add(a, b) { return a + b; }
function add1(a) { return a + 1; }
function lt5(a) { return a < 5; }
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
JS map |
| ready |
Native map |
| ready |
JS reduce |
| ready |
Native reduce |
| ready |
JS reduceRight |
| ready |
Native reduceRight |
| ready |
JS filter |
| ready |
Native filter |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.