Script Preparation code:
x
 
function m(l1, l2) {
    var u = [];
    for (var i = 0; i < l1.length; i++) {
        u.push(l1[i]);
    }
    for (var j = 0; j < l2.length; j++) {
        var dupe = false;
        for (var i = 0; i < l1.length; i++) {
            if (l1[i] === l2[j]) {
                dupe = true;
            }
        }
        if (!dupe) {
            u.push(l2[j]);
        }
    }
    return u;
}
function n(l1, l2) {
    let combined = [].concat(l1, l2);
    return [...new Set(combined)];
}
Array.prototype.unique = function() {
    var a = this.concat();
    for(var i=0; i<a.length; ++i) {
        for(var j=i+1; j<a.length; ++j) {
            if(a[i] === a[j])
                a.splice(j--, 1);
        }
    }
    return a;
};
function usingForEach(l1,l2){
    let u = []
    l1.forEach(function(item){
            u.push(item);
    });
    l2.forEach(function(item){
        if(u.indexOf(item)<0)
            u.push(item);
    });
    return u;
}
var a = [1, 2, 3, 4, 5];
var b = [3, 3, 4, 5, 5, 6, 7];
Tests:
  • m

     
    var testM = m(a, b);
  • n

     
    var testN = n(a, b);
  • unique

     
    var testUnique = a.concat(b).unique();
  • y

     
    var y = usingForEach(a,b);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    m
    n
    unique
    y

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 OPR/90.0.4480.117
Opera 90 on Windows
View result in a separate tab
Test name Executions per second
m 3256162.5 Ops/sec
n 959444.9 Ops/sec
unique 1648508.5 Ops/sec
y 3039958.0 Ops/sec