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.
one year ago
User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 OPR/101.0.0.0 (Edition std-1)
Test name Executions per second
Object.values(obj) 5857407.5 Ops/sec
_.values(obj) 5716547.0 Ops/sec
for...in 12624740.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