Concatenating prefix of one array with the reversed suffix of another array Given two arrays and two indices, I need to concatenate the prefix of the first array and the reversed prefix of the second array.

For example:

// Input
arr1 = [1,2,3,4,5,6,7,8,9];
arr2 = [10,11,12,13,14,15];
ind1 = 6;
ind2 = 3;

// Output
arr = [1,2,3,4,5,6,12,11,10];


I have implemented two different functions for this purpose:

function func1(arr1,arr2,ind1,ind2)
{
    let arr = [];
    for (let n = 0; n &lt;= ind1; n++)
        arr.push(arr1[n]);
    for (let n = ind2; n &gt;= 0; n--)
        arr.push(arr2[n]);
    return arr;
}

function func2(arr1,arr2,ind1,ind2)
{
    return arr1.slice(0, ind1 + 1).concat(arr2.slice(0, ind2 + 1).reverse());
}


And now I would like determine which one of them is better, using this performance analysis:

function measure(func,arr1,arr2,ind1,ind2)
{
    let t0 = performance.now();
    arr = func(arr1,arr2,ind1,ind2);
    let t1 = performance.now();
    return t1 - t0;
}

results = '';

for (let len = 10; len &lt;= 120; len += 10)
{
    let func1Count = 0;
    let func2Count = 0;
    for (let i=0; i&lt;1000000; i++)
    {
        let arr1 = new Array(len);
        let arr2 = new Array(len);
        let ind1 = Math.floor(Math.random()*len);
        let ind2 = Math.floor(Math.random()*len);
        func1Count += measure(func1,arr1,arr2,ind1,ind2);
        func2Count += measure(func2,arr1,arr2,ind1,ind2);
    }
    if (func1Count &lt; func2Count)
        results += 'len='+len+': func1 is better ('+func1Count+' vs '+func2Count+')\n';
    else
        results += 'len='+len+': func2 is better ('+func1Count+' vs '+func2Count+')\n';
}

alert(results);


The test above indicates that the first function is better if the array length is (approximately) 80 or less, and that the second function is better otherwise.

I would like to ensure the correctness of my performance analysis.

In addition, I should note that this code will eventually run on server side (i.e., NodeJS), but I am testing it on client side (i.e., a browser). So if this method is fundamentally wrong (i.e., testing a server-side code over a client-side platform), then I would be happy to be notified.
The only note I can make is that in func1 and func2 you have an "API bug": the indices are "included" in the array. Consider this example:

[1, 2, 3, 4].slice(1, 3)


will produce [2, 3], so the point is that 3 in slice(1, 3) is not included. This does not happen only in Javascript, but also in other languages as well (I know Java does it that way). So the only advice would be to write your functions as

function func1(arr1,arr2,ind1,ind2)
{
    let arr = [];
    for (let n = 0; n &lt; ind1; n++)
        arr.push(arr1[n]);
    for (let n = ind2 - 1; n &gt;= 0; n--)
        arr.push(arr2[n]);
    return arr;
}

function func2(arr1,arr2,ind1,ind2)
{
    return arr1.slice(0, ind1).concat(arr2.slice(0, ind2).reverse());
}


Also, it is good to have a single space after each comma , in the function parameter list.