<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.js"></script>
var person = {name: 'Frederick', lastName: 'Corcino Alejo'};
_.assign({}, person, {age: 15});
Object.assign({}, person, {age: 15});
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Lodash Assing | |
Native Assing |
Test name | Executions per second |
---|---|
Lodash Assing | 10028608.0 Ops/sec |
Native Assing | 24558486.0 Ops/sec |
Let's break down the provided JSON and explain what's being tested.
What is being tested?
The benchmark measures the performance of two approaches for assigning values to an object: Object.assign
(native JavaScript) and _.assign
from the Lodash library.
Options compared:
Object.assign
): This is a built-in method in JavaScript that creates a new object by copying properties from one or more source objects._._assign
): The Lodash library provides a utility function _.
for functional programming, which includes an assign
method that can be used to merge objects.Pros and cons of each approach:
Object.assign
):_.assign
, may not work with all data types (e.g., null or undefined values)._._assign
):Other considerations:
The benchmark also records information about the test device, browser, operating system, and number of executions per second. This data can be useful for identifying patterns or trends in performance across different devices and browsers.
Library description (Lodash):
Lodash is a popular JavaScript utility library that provides a collection of functions for functional programming tasks, including array manipulation, string formatting, and object manipulation (like _.assign
).
Special JS feature/syntax: None mentioned
Since there's no specific JavaScript feature or syntax being tested in this benchmark, we can focus on the performance comparison between native JavaScript and Lodash's _.assign
.
Alternatives:
Other alternatives for assigning values to an object include:
Object.create()
: A method that creates a new object by copying properties from a prototype.{ ... }
) with destructuring assignment.new
keyword and assigning properties manually.Keep in mind that these alternatives may have different performance characteristics compared to native JavaScript or Lodash's _.assign
.