Tests:
  • reduce

    x
     
    const firstArr = new Array(200).fill(undefined).map((val, i) => `item${i}`)
    const secondArr = new Array(250).fill(undefined).map((val, i) => `item${i}`)
    const result = secondArr.reduce(
      (acc, item) => {
        return acc.includes(item) ? acc : [...acc, item]
      },
      [...firstArr]
    )
  • loop

     
    const firstArr = new Array(200).fill(undefined).map((val, i) => `item${i}`)
    const secondArr = new Array(250).fill(undefined).map((val, i) => `item${i}`)
    const result = []
    for (let i = 0; i < firstArr.length; i++) {
      if (result.indexOf(firstArr[i]) == -1) result.push(firstArr[i])
    }
    for (let i = 0; i < secondArr.length; i++) {
      if (result.indexOf(secondArr[i]) == -1) result.push(secondArr[i])
    }
  • concat and filter

     
    const firstArr = new Array(200).fill(undefined).map((val, i) => `item${i}`)
    const secondArr = new Array(250).fill(undefined).map((val, i) => `item${i}`)
    const concatArr = firstArr.concat(secondArr)
    const result = concatArr.filter((item, idx) => concatArr.indexOf(item) === idx)
  • set

     
    const firstArr = new Array(200).fill(undefined).map((val, i) => `item${i}`)
    const secondArr = new Array(250).fill(undefined).map((val, i) => `item${i}`)
    const result = [...new Set([...firstArr, ...secondArr])]
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    reduce
    loop
    concat and filter
    set

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.2 Safari/605.1.15
Safari 16 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
reduce 6552.7 Ops/sec
loop 5901.5 Ops/sec
concat and filter 4937.6 Ops/sec
set 27704.6 Ops/sec