Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash merge vs object.assign vs spread on empty object
(version: 0)
Comparing performance of:
lodash merge vs object.assign vs spread
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Tests:
lodash merge
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = _.merge({}, a, b);
object.assign
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = Object.assign({}, a, b);
spread
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = { ...a, ...b };
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash merge
object.assign
spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help you understand the JavaScript microbenchmark on MeasureThat.net. **Overview** The benchmark compares three approaches for merging two objects: 1. `_.merge()` from Lodash 2. `Object.assign()` 3. The spread operator (`{ ... }`) **Options Compared** * `_._merge()` from Lodash: A utility function that merges two or more objects into one, overriding properties with the same name. * `Object.assign()`: A built-in JavaScript method that copies the values of all enumerable own properties from one or more source objects to a target object. * The spread operator (`{ ... }`): A syntax feature in modern JavaScript that allows creating a new object by spreading the properties of an existing object. **Pros and Cons** 1. `_._merge()` (Lodash): * Pros: Fast, efficient, and easy to use. Lodash is a popular utility library, and this function is well-maintained. * Cons: Requires importing Lodash, which may slow down the test. 2. `Object.assign()`: * Pros: Built-in JavaScript method, fast, and widely supported. * Cons: May not be as intuitive or readable as other approaches. 3. Spread operator (`{ ... }`): * Pros: Simple, concise, and easy to read. * Cons: Only available in modern JavaScript environments (ECMAScript 2018+). **Library and Syntax** The benchmark uses the Lodash library for the `_._merge()` function. Note that the spread operator is a syntax feature introduced in ECMAScript 2018. If you're using an older version of JavaScript, this approach won't work. **Test Case Breakdown** Each test case defines a simple scenario: 1. Two objects `a` and `b` with some properties. 2. A new object `c` is created by merging `a` and `b`. The benchmark measures the execution time for each approach to create `c`. The raw UA string, browser version, device platform, operating system, executions per second, and test name are all provided. **Other Alternatives** Other approaches for merging objects could include: * Using the `Object.create()` method and setting properties. * Utilizing a custom merge function or algorithm. * Leveraging other libraries like `merge-deep` or ` deep-merge`. However, these alternatives are not tested in this specific benchmark.
Related benchmarks:
lodash merge vs object.assign vs spread new obj
lodash.assign vs object.assign vs spread
Array Properties Merge: Lodash merge vs Object.assign
lodash merge vs object.assign vs spread (no intermediate vars)
lodash assign vs object.assign vs spread operator - variable and constant
Comments
Confirm delete:
Do you really want to delete benchmark?