Set vs Array remove element from big list

JavaScript performance comparison

Test case created by gartz

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  let arr = Array(1000).fill(null).map(v => ({}));
  const set = new Set(arr);
  
  const begin = arr[4];
  const middle = arr[531]
  const end = arr[998];
  

};
</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 remove
set.delete(begin);
set.delete(middle);
set.delete(end);
pending…
Array remove
arr = arr.filter(i => begin !== i);
arr = arr.filter(i => middle !== i);
arr = arr.filter(i => end !== i);
pending…
Array splice
arr.splice(arr.indexOf(begin), 1);
arr.splice(arr.indexOf(middle), 1);
arr.splice(arr.indexOf(end), 1);
pending…
Array reducer
arr = arr.reduce((a, i) => { if(i !== begin) { a.push(i); } return a}, []);
arr = arr.reduce((a, i) => { if(i !== middle) { a.push(i); } return a}, []);
arr = arr.reduce((a, i) => { if(i !== end) { a.push(i); } return a}, []);
pending…

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

Compare results of other browsers

0 Comments