HTML Preparation code:
AخA
 
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js"></script>
Script Preparation code:
 
var obj = Array.from({ length: 10000 }).map((value, i) => i).reduce((val, v) => { val[v] = v; return val; }, {});
var arr = [...Array.from(10000).keys()];
Tests:
  • lodash.each

     
    const a = [];
    _.each(obj, function(v,k) {
      a.push(v);
    });
  • native for-of w/ entries

     
    const a = [];
    for (const [k, v] of Object.entries(obj)) {
      a.push(v);
    }
  • native forEach w/ entries

     
    const a =[];
    Object.entries(obj).forEach(function(v, k) {
      a.push(v);
    })
  • vanilla for-loop w/ Object.keys

     
    const a=[];
    const keys = Object.keys(obj);
    for (let i = 0; i < keys.length; i++) { const v = obj[keys[i]]; 
                                          a.push(v);}
  • vanilla for-loop w/ Object.entries

     
    const a=[];
    const entries = Object.entries(obj);
    for (let i = 0; i < entries.length; i++) { const [k, v] = entries[i];
                                             a.push(v);}
  • vanilla for-loop w/ Object.values (no keys)

     
    const a =[];
    const values = Object.values(obj);
    for (let i = 0; i < values.length; i++){ 
    a.push(values[i]);}
  • native forEach w/ Object.values (no keys)

     
    const a =[];
    Object.values(obj).forEach(function(v) {
    a.push(v);
    })
  • native for-in

     
    const a =[];
    for (const prop in obj) { if (obj.hasOwnProperty(prop)) { const v = obj[prop];
                                                            a.push(v);} }
  • map

     
    const results = arr.map(x=>x);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    lodash.each
    native for-of w/ entries
    native forEach w/ entries
    vanilla for-loop w/ Object.keys
    vanilla for-loop w/ Object.entries
    vanilla for-loop w/ Object.values (no keys)
    native forEach w/ Object.values (no keys)
    native for-in
    map

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Chrome 109 on Windows
View result in a separate tab
Test name Executions per second
lodash.each 1936.6 Ops/sec
native for-of w/ entries 966.7 Ops/sec
native forEach w/ entries 792.0 Ops/sec
vanilla for-loop w/ Object.keys 615.0 Ops/sec
vanilla for-loop w/ Object.entries 992.0 Ops/sec
vanilla for-loop w/ Object.values (no keys) 14435.5 Ops/sec
native forEach w/ Object.values (no keys) 10951.5 Ops/sec
native for-in 472.7 Ops/sec
map 9311743.0 Ops/sec