Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36
Chrome 99
Linux
Desktop
2 years ago
Test name Executions per second
UniqBy 2001372.6 Ops/sec
Set 2492922.5 Ops/sec
HTML Preparation code:
x
 
1
2
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Tests:
  • UniqBy

     
    const a = [{a:1},{a:1},{a:1},{a:2},{a:2},{a:3}]
    const uniques = _.uniqBy(a, 'a')
  • Set

     
    const a = [{a:1},{a:1},{a:1},{a:2},{a:2},{a:3}]
    const uniques = [];
    const set = new Set();
    for (const e of a) {
      if(!set.has(e.a)) {
        uniques.push(e);
        set.add(e.a);
      }
    }