<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var obj1 = { adalet: false }
var obj2 = { barış: false }
var obj3 = { özgürlük: false }
_.merge({}, obj1, obj2, obj3)
Object.assign({}, obj1, obj2, obj3)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Lodash | |
Native |
Test name | Executions per second |
---|---|
Lodash | 1702846.0 Ops/sec |
Native | 7873787.5 Ops/sec |
Let's dive into the world of MeasureThat.net and explore what's being tested in this benchmark.
Benchmark Overview
The benchmark compares two approaches for merging objects: Lodash's _merge
function and the native Object.assign
method.
Options Compared
The test cases compare:
_merge
function: A utility function from the popular JavaScript library Lodash that merges multiple objects into a single object.Object.assign
method: A built-in JavaScript method for merging two or more objects into a new object.Pros and Cons
Here are some pros and cons of each approach:
_merge
function:Object.assign
method:_merge
function (although not always significant).Other Considerations
Individual Test Cases
The individual test cases measure the performance of each approach:
_merge
function: _.merge({}, obj1, obj2, obj3)
This test case uses Lodash's _merge
function to merge three simple objects (obj1
, obj2
, and obj3
) into a single object.Object.assign
method: Object.assign({}, obj1, obj2, obj3)
This test case uses the native Object.assign
method to achieve the same result as Lodash's _merge
function.Conclusion
The MeasureThat.net benchmark provides valuable insights into the performance differences between using an external library (Lodash) and a built-in JavaScript method (Object.assign). Understanding these trade-offs can help developers make informed decisions when working with object merges in their projects.