Set vs Filter

JavaScript performance comparison

Test case created by brianbancroft

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const generateArr = () => {
      const arr = [];
      for (let i = 0; i < 1000; i++) { arr.push(parseInt(Math.random() * 10)); }
      return arr;
  };
  
  const arr = generateArr()

};

Benchmark.prototype.teardown = function() {
  delete arr

};
</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
Array Notation
const arrayFilter = arr.filter((i, index) => arr.indexOf(i) === index);
pending…
Set Notation
const newSet = new Set(arr);
pending…

Compare results of other browsers

Revisions

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

0 Comments