Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.fromEntries vs lodash fromPairs
(version: 0)
Comparing performance of:
Object.fromEntries vs _.fromPairs
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:
Object.fromEntries
var a = [['a', 1], ['b', 2], ['c', 3]]; var b = Object.fromEntries(a);
_.fromPairs
var a = [['a', 1], ['b', 2], ['c', 3]]; var b = _.fromPairs(a);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.fromEntries
_.fromPairs
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Browser/OS:
Chrome 144 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.fromEntries
16691485.0 Ops/sec
_.fromPairs
44561244.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is being tested?** The provided JSON represents a benchmark test between two approaches: `Object.fromEntries` and `lodash fromPairs`. The benchmark is designed to compare the performance of these two methods for converting an array of key-value pairs to an object. **Options compared:** * `Object.fromEntries`: A built-in JavaScript method introduced in ECMAScript 2017, which converts an iterable of key-value pairs to an object. * `lodash fromPairs`: A utility function from the popular Lodash library, which achieves the same result as `Object.fromEntries`. **Pros and Cons:** * **`Object.fromEntries`**: + Pros: Built-in method, efficient, and widely supported across browsers and Node.js versions. + Cons: May have slower performance compared to optimized libraries like Lodash. * **`lodash fromPairs`**: + Pros: Optimized for performance, compatible with older browsers and Node.js versions, and often used in production code. + Cons: Requires an external dependency (Lodash library) and may have a larger size overhead. **Library:** The `_.fromPairs` function is part of the Lodash library, which provides a comprehensive set of utility functions for JavaScript developers. The purpose of Lodash is to simplify common tasks and improve code readability by providing convenient functions for array manipulation, object creation, and more. **Special JS feature or syntax:** None mentioned in this benchmark test. **Benchmark preparation code:** The script preparation code includes an HTML link to include the Lodash library, which is required for the `_.fromPairs` function. The actual benchmark code is not provided, but it's likely that a simple array of key-value pairs is created and passed to both `Object.fromEntries` and `_.fromPairs` functions. **Other alternatives:** If you're interested in exploring other options, here are a few: * **`Array.prototype.reduce()`**: Another built-in JavaScript method that can be used to create an object from an array of key-value pairs. However, this approach might have higher overhead due to the need to iterate over the array. * **`Object.assign()`**: A built-in JavaScript function that can be used to merge objects, but it's not designed for creating an object from an array of key-value pairs. Keep in mind that these alternatives might not provide the same performance as `Object.fromEntries` or optimized libraries like Lodash.
Related benchmarks:
lodash.keys [4.17.11] vs Object.keys
isEmpty vs Object.keys
Lodash IsEmpty for objects
Comparing performance of native .length and Lodash _.isEmpty v2
lodash isobject vs typeof vs toString
Comments
Confirm delete:
Do you really want to delete benchmark?