unique

JavaScript performance comparison

Revision 2 of this test case created by Mike Sherov

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  let a = [];
  for (let i = 0; i < 1000; i++) a.push(i, i);

};
</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
filter
a.filter((curr, i) => a.indexOf(curr) === i)
pending…
object based
d={}; a.forEach(function(x) { d[x]=true; }); Object.keys(d);
pending…
filter self
a.filter((curr, i, self) => self.indexOf(curr) === i)
pending…
from new set
Array.from(new Set(a))
pending…
reduce spread
a.reduce((acc, curr) => (!acc.includes(curr) ? [...acc, curr] : acc), [])
pending…
reduce push
a.reduce((acc, curr) => (!acc.includes(curr) && acc.push(curr) && acc || acc), [])
pending…
spread set
[...new Set(a)]
pending…
reduce concat
a.reduce((acc, curr) => (!acc.includes(curr) ? acc.concat(curr) : acc), [])
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