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?
It seems that when you need concat large arrays, the Array.prototype.push() will save you tons of time. For all other operations the array.concat would be the best option.
<script>
var bigArray = [],
l = 20,
i = 0,
n = 0,
array;
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 |
[].push |
| ready |
Array.prototype.push.call |
| ready |
Array.prototype.push.apply |
| ready |
[].unshift |
| ready |
Array.prototype.unshift.call |
| ready |
Array.prototype.unshift.apply |
| ready |
Optimum loop |
| ready |
Optimum loop* |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.