Performance of Object.values(obj) vs_.values() vs for...in to extract values from an object

Compare performance between the native Object.values(obj) function vs the lodash _.values() option and a function that extracts the values of an object using a for...in loop.
3 years ago
User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36
Test name Executions per second
Object.values(obj) 2743749.0 Ops/sec
_.values(obj) 2918252.8 Ops/sec
for...in 6444792.0 Ops/sec
HTML Preparation code:
AخA
 
1
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.core.js"></script>
Script Preparation code:
 
function extractValues(obj) {
   const t = [];
   for(var key in obj) { t.push(obj[key]); }
   return t;
}
Tests:
  • Object.values(obj)

     
    var a = { a: 1, b: 2, c: 3};
    Object.values(a);
  • _.values(obj)

     
    var a = { a: 1, b: 2, c: 3};
    _.values(a);
  • for...in

     
    var a = { a: 1, b: 2, c: 3};
    extractValues(a);
Open this result on MeasureThat.net