Convert between Array and Set

Benchmark created on


Setup

const srcArray = ['1', '2', '3']
const srcSet = new Set(['1', '2', '3'])

Test runner

Ready to run.

Testing in
TestOps/sec
Array -> Set: new Set
const set = new Set(srcArray)
ready
Set -> Array: Array.from()
const arr = Array.from(srcSet)
ready
Set -> Array: [ ...Set ]
const arr = [...srcSet]
ready
Set -> Array: forEach() + push()
const arr = []
srcSet.forEach(item => arr.push(item))
ready
Set -> Array: for + push()
const arr = []
for (let item of srcSet) {
  arr.push(item)
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.