Sort

JavaScript performance comparison

Test case created by omeid

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const scale = (num) => {
  // scale 0 to 5000 to 97 to 122.
    return num * 25 / (5000) + 97;
  }
  
  const list = (new Array(5000)).fill().map((i, index) => String.fromCharCode(scale(index))).sort(() => Math.random() - 0.5)

};
</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
sortuniq
list.sort().reduce((list, c) => { if (list[list.length - 1] !== c) list.push(c); return list }, [])
pending…
filteruniq
(list.filter((el, i, s) => s.indexOf(el) === i))
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