JsUniqueArray

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [1,1,'1','1',0,0,'0','0',undefined,undefined,null,null,NaN,NaN,{},{},[],[],/a/,/a/];
  
  function uniqueSet(arr){
      var set = new Set(arr);
      return Array.from(set);
  }
  
  function uniqueMap(arr) {
      var ret = [];
      var len = arr.length;
      var tmp = new Map();
      for(var i=0; i<len; i++){
          if(!tmp.get(arr[i])){
              tmp.set(arr[i], 1);
              ret.push(arr[i]);
          }
      }
      return ret;
  }
  
  function uniqueIncludes(arr) {
      var ret = [];
      arr.forEach(function(item){
          if(!ret.includes(item)){
              ret.push(item);
          }
      });
      return ret;
  }

};
</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
uniqueSet(arr);
pending…
Map
uniqueMap(arr);
pending…
Array.Includes()
uniqueIncludes(arr);
pending…

Revisions

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

0 Comments