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
Compares techniques for extending an array with another array.
See http://stackoverflow.com/questions/1374126/how-to-append-an-array-to-an-existing-javascript-array
<script>
/**
* extend an array with another array. See http://stackoverflow.com/a/1374131/1280629
**/
Array.prototype.extend_push_apply = function(array) {
this.push.apply(this, array)
}
Array.prototype.extend_for_loop = function(array) {
for (var i = 0; i < array.length; ++i) {
this.push(array[i]);
};
}
Array.prototype.extend_forEach = function (array) {
array.forEach(function(x) {this.push(x)}, this);
}
Array.prototype.extend_splice = function (array) {
array.unshift(array.length)
array.unshift(this.length)
Array.prototype.splice.apply(this,array)
array.shift() // restore b
array.shift() //
}
var short_array = [];
var length = 10000
while(length--){
short_array.push(Math.random()*3000);
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Extend via push apply |
| ready |
Extend via splice |
| ready |
Extend via push for loop |
| ready |
Extend via push forEach |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.