# concat perf test CORRECT

## JavaScript performance comparison

Test case created

## Preparation code

``<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);</script>``

## Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
[].concat.apply([], arrays)
``tests.forEach(function(arrays){result = [].concat.apply([], arrays);})``
pending…
repeated concat with for loop
``tests.forEach(function(arrays){result = [];for(var i=0; i<arrays.length; i++)    result = result.concat(arrays[i]);})``
pending…
arrays.reduce(function(a,b){return a.concat(b)}, [])
``tests.forEach(function(arrays){result = arrays.reduce(function(a,b){return a.concat(b)}, [])})``
pending…
repeated push(#,#,...,#) with for loop
``tests.forEach(function(arrays){result = [];for(var i=0; i<arrays.length; i++)    result.push.apply(result, arrays);})``
pending…

## Revisions

You can edit these tests or add even more tests to this page by appending `/edit` to the URL. Here’s a list of current revisions for this page:

Comment form temporarily disabled.