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
There are different ways of adding concat arrays. You can use array.concat or leverage the Array.prototype methods. So, what will be faster? Array.concat because, it's build for it.. Or a prototype function?
Not sure we could have a final conclusion, since it really depend on your browser. You may also be interested in concat-arguments test cases.
Prototype function are cached in local scope, to avoid any influence of referencing prototyped function. This is a good coding practice in general. Deleted test cases where all incorrect additions of single element containing the array which could not be compared with array concatenation.
<script>
var bigArray = [],
l = 20,
i = 0,
n = 0,
array, concat = Array.prototype.concat,
push = Array.prototype.push,
unshift = Array.prototype.unshift;
while (++i < l) { // forces value, no undefined; optimized
bigArray[i] = 1;
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
[].concat |
| ready |
Array.prototype.concat.call |
| ready |
Array.prototype.concat.apply |
| ready |
deleted |
| ready |
deleted |
| ready |
Array.prototype.push.apply |
| ready |
deleted |
| ready |
deleted |
| ready |
Array.prototype.unshift.apply |
| ready |
Optimum increasing loop |
| ready |
Optimum decreasing loop |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.