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 = function(array) {
this.push.apply(this, array)
}
Array.prototype.extend_for_loop = function(array) {
for (var i = 0, len = array.length; i < len; ++i) {
this.push(array[i]);
};
}
Array.prototype.pre_extend_for_loop = function(array) {
var i = this.length;
this.length += array.length;
for (var j = 0, len = array.length; j < len; ++i, ++j) {
this[i] = array[j];
};
}
var short_array = []
short_array.length = 2;
var long_array = []
long_array.length = 5;
</script>
var array_to_extend = [];
Ready to run.
Test | Ops/sec | |
---|---|---|
Extend via push apply - short array |
| ready |
Extend via push for loop - short array |
| ready |
Extend via push for loop (with pre-lengthening of dest array)- short array |
| ready |
Extend via push apply - long array |
| ready |
Extend via push for loop - long array |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.