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
"use strict";
function trampoline(fn){
return function(/*args*/){
var res = fn.apply(this, arguments);
while(res instanceof Function){
res = res();
}
return res;
}
}
// Generate an array of numbers in a given range.
// Tail Recursive implementation
function _rangetr(s, e, res) {
res = res || [];
res.push(s);
return s == e ? res : function() { return _rangetr(s<e ? ++s : --s, e, res); };
}
// Generate an array of numbers in a given range.
// Tail Recursive implementation
function rangetr(s, e, res) {
res = res || [];
res.push(s);
return s == e ? res : rangetr(s<e ? ++s : --s, e, res);
}
// Generate an array of numbers in a given range.
// Recursive implementation
function ranger(s, e) {
var res = [];
res.push(s);
return s == e ? res : res.concat(ranger(s<e ? ++s : --s, e));
}
// Generate an array of numbers in a given range.
// Iterative implementation
function range(s, e) {
var res = [];
while (s != e) {
res.push(s);
s < e ? s++ : s--;
}
res.push(s);
return res;
}
// Babel transpiled tail-call optimization
function rangetr_babel(_x, _x2, _x3) {
var _again = true;
_function: while (_again) {
var s = _x,
e = _x2,
res = _x3;
_again = false;
res = res || [];
res.push(s);
if (s == e) {
return res;
} else {
_x = s < e ? ++s : --s;
_x2 = e;
_x3 = res;
_again = true;
continue _function;
}
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Iteration |
| ready |
Recursion |
| ready |
Tail Recursive |
| ready |
Tail Recursive w/ Trampoline |
| ready |
Babel Tail Call Optimized |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.