HTML Preparation code:
AخA
 
1
 <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js" type="text/javascript"></script>
2
    <script src="https://cdn.rawgit.com/mariocasciaro/object-path/master/index.js"></script>
Script Preparation code:
x
 
var obj = {
  stuff: {
    things: {
      stuff: 'things',
      things: 'stuff',
      other: {
        stuff: 'things'
      }
    }
  }
};
Tests:
  • Lodash get

     
    _.get(obj, 'stuff.things.other.stuff');
  • object path

     
    objectPath.get(obj, 'stuff.things.other.stuff');
  • Native

     
    obj.stuff && obj.stuff.things && obj.stuff.things.other && obj.stuff.things.other.stuff;
  • Optional chaining

     
    obj.stuff?.things?.other?.stuff;
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Lodash get
    object path
    Native
    Optional chaining

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 OPR/99.0.0.0
Opera 99 on Linux
View result in a separate tab
Test name Executions per second
Lodash get 2240780.5 Ops/sec
object path 996849.2 Ops/sec
Native 3179911.5 Ops/sec
Optional chaining 12580500.0 Ops/sec