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
<script>
function randInt(n) {
// return random int in range [0,n)
return Math.floor(Math.random()*n)
}
function range(a,b) {
// > range(2,5)
// [2, 3, 4]
if (b===undefined) {
b=a; a=0;
}
return a==b ? [] : range(a,b-1).concat(b-1);
}
// Make 15 testscases. Each testcase has between 3-8 arrays of length 0-100 which must be combined.
function makeArrays() {
return range(3+randInt(5)).map(function(){return range(randInt(100))})
}
var tests = range(15).map(makeArrays);
var realSolutions = tests.map(function(arrays){return [].concat.apply([], arrays)});
</script>
if (JSON.stringify(results) != JSON.stringify(realSolutions)) {
console.log('got: ', results, 'expected: ', realResults);
throw "This test case "+this+" returns the wrong results. See console."
}
Ready to run.
Test | Ops/sec | |
---|---|---|
[].concat.apply([], arrays) |
| ready |
repeated concat with for loop |
| ready |
arrays.reduce(function(a,b){return a.concat(b)}, []) |
| ready |
push each array one-by-one: push(#,#,...,#), push(#,#,...,#), ... |
| ready |
push each element one-by-one: push(#), push(#), ... |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.