Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.fromPairs vs Object.fromEntries
(version: 0)
Comparing performance of:
Object.fromEntries vs _.fromPairs
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.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 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0
Browser/OS:
Firefox 123 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.fromEntries
8251895.5 Ops/sec
_.fromPairs
12006329.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help you understand the provided benchmark. **What is being tested?** The benchmark compares two approaches for creating an object from key-value pairs: `_.fromPairs` (a function from the Ramda library) and `Object.fromEntries` (a built-in JavaScript method). **Options compared:** 1. **Ramda's _.fromPairs**: This function creates an object from key-value pairs, where each pair is passed as an array of two elements. 2. **JavaScript's Object.fromEntries**: This method creates an object from key-value pairs, where each pair is passed as an iterable (such as an array or a Map). **Pros and Cons:** 1. **Ramda's _.fromPairs**: * Pros: + Simple and concise syntax. + Works with any type of iterable input (not just arrays). * Cons: + May have performance overhead due to the need to bind the Ramda library. 2. **JavaScript's Object.fromEntries**: * Pros: + Built-in method, so no additional library needed. + Often faster than other approaches since it's optimized by JavaScript engines. * Cons: + Syntax can be less readable for some developers, especially those not familiar with the method. **Other considerations:** 1. **Browser support**: Both methods are supported in modern browsers, but `Object.fromEntries` is more widely supported due to its built-in nature. 2. **Performance**: The benchmark measures executions per second, which indicates the performance difference between the two approaches. **Library and syntax used:** The Ramda library provides a simple way to work with functions and data transformations. `_fromPairs` is one of the utility functions provided by Ramda. **Special JS feature or syntax:** There are no special features or syntaxes being tested in this benchmark, but it's worth noting that `Object.fromEntries` is a relatively new method introduced in ECMAScript 2017 (ES2017). **Alternatives:** Other approaches to creating an object from key-value pairs include: 1. Using the `reduce()` method with an initial value of `{}`: ```javascript var obj = {}; a.reduce((obj, [key, value]) => ({ ...obj, [key]: value }), obj); ``` 2. Using the `Map` constructor and then spreading its entries to create a new object: ```javascript var map = new Map(a.map(([key, value]) => [key, value])); var obj = Object.fromEntries(map.entries()); ``` 3. Manually iterating over the input array and creating an object property for each pair. These alternatives may have different performance characteristics or requirements (e.g., memory usage), depending on the specific use case and constraints.
Related benchmarks:
ramdajs contains
ramda toPairs vs. Object.entries
Lodash vs Ramda fromPairs
Lodash vs Ramda vs Native fromPairs
Ramda range vs Array.from
Comments
Confirm delete:
Do you really want to delete benchmark?