HTML Preparation code:
x
 
1
2
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
 
var smalldata = [1,2,3,4,5,'ok','abc','def',null,undefined,1,2,3,'ok'];
var bigdata = [1,2,3,4,5,'ok','abc','def',null,undefined,1,2,3,'ok',1,2,3,4,5,'ok','abc','def',null,undefined,1,2,3,'ok',1,2,3,4,5,'ok','abc','def',null,undefined,1,2,3,'ok',1,2,3,4,5,'ok','abc','def',null,undefined,1,2,3,'ok',1,2,3,4,5,'ok','abc','def',null,undefined,1,2,3,'ok',1,2,3,4,5,'ok','abc','def',null,undefined,1,2,3,'ok',1,2,3,4,5,'ok','abc','def',null,undefined,1,2,3,'ok',1,2,3,4,5,'ok','abc','def',null,undefined,1,2,3,'ok',1,2,3,4,5,'ok','abc','def',null,undefined,1,2,3,'ok'];
var uniq = (arr) => {
  var dups = new Set();
  return arr.filter((v) => {
    if (dups.has(v)) {
      return false;
    }
    dups.add(v);
    return true;
  });
};
var uniqset = (arr) => [...(new Set(arr))];
Tests:
  • lodash/uniq

     
    _.uniq(smalldata);
    _.uniq(bigdata);
  • filter+set

     
    uniq(smalldata);
    uniq(bigdata);
  • array→set→array

     
    uniqset(smalldata);
    uniqset(bigdata);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    lodash/uniq
    filter+set
    array→set→array

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
Chrome 87 on Mac OS X 11.0.1
View result in a separate tab
Test name Executions per second
lodash/uniq 154580.6 Ops/sec
filter+set 290562.5 Ops/sec
array→set→array 325574.5 Ops/sec