Removing Duplicates

JavaScript performance comparison

Test case created by chmelevskij

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  arr = Array.from(Array(10000), () => parseInt(Math.random() * 100)).sort()
  

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Set
// Set
set1 = [...new Set(arr)]
pending…
Map
// With Map
map = new Map();
set2 = []

for(const i of arr) {
    if(!map.has(i)){
        map.set(i, true)
        set2.push(i)
    }
}
pending…
Array
arr.sort()

j = 0
set3 = []
for(let i = 0; i < arr.length - 1; i++) {
    if(arr[i] !== arr[i+1]) {
        set3[j] = arr[i]
        j += 1
    }
}
pending…

Revisions

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

0 Comments