Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Compare the new ES6 spread operator with Ramda assoc (10000000 keys)
(version: 0)
Comparing performance of:
spread operator vs Ramda assoc vs Object.assign
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.js"></script>
Script Preparation code:
var params = { "a": 1, "b": 2 }; for(var i = 0; i<10000000; i++); params['x'+i] = i
Tests:
spread operator
var result = { ...params, "c": 3 };
Ramda assoc
var result = R.assoc("c", 3, params);
Object.assign
var result = Object.assign({}, params, {c:3});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
spread operator
Ramda assoc
Object.assign
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
spread operator
64261044.0 Ops/sec
Ramda assoc
21495346.0 Ops/sec
Object.assign
19850704.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested, compared, and some pros and cons of different approaches. **Benchmark Overview** The benchmark measures the performance of three methods to merge an object with a new set of key-value pairs: 1. ES6 spread operator (`{ ...params, "c": 3 }`) 2. Ramda's `assoc` function (`R.assoc("c", 3, params)`) 3. `Object.assign()` method (`Object.assign({}, params, { c: 3 })`) **Script Preparation Code** The script preparation code creates a large object with 10 million keys and a single value (`params = { "a": 1, "b": 2 }`). Then, it iterates from 0 to 9,999,999, assigning each iteration number to a new property on the `params` object. **Html Preparation Code** The HTML preparation code includes a script tag that loads Ramda version 0.25.0, which is used in one of the benchmark test cases. **Individual Test Cases** Each test case has a specific `Benchmark Definition` code that creates a new object by merging the original `params` object with a new set of key-value pairs using the corresponding method: 1. Spread operator: `{ ...params, "c": 3 }` 2. Ramda's `assoc`: `R.assoc("c", 3, params)` 3. `Object.assign()` method: `Object.assign({}, params, { c: 3 })` **Library: Ramda** Ramda is a functional programming library for JavaScript that provides a set of utility functions for working with arrays and objects. In this benchmark, Ramda's `assoc` function is used to merge the original object with a new key-value pair. Pros: * Easy to read and write * Does not modify the original object * Can be composed with other functions Cons: * Slower than native JavaScript methods (e.g., spread operator, `Object.assign()`) * Requires additional setup with Ramda library **Other Alternatives** 1. **Native JavaScript spread operator**: `{ ...params, "c": 3 }` is a built-in JavaScript feature that allows merging objects using the spread operator. Pros: * Fast and efficient * Native support in most browsers Cons: * Introduced in ECMAScript 2018 (ES2018) 2. **Object.assign() method**: `Object.assign()` is a built-in JavaScript method for merging objects. Pros: * Fast and efficient * Wide browser support Cons: * May modify the original object if not used carefully **Special JS Feature/ Syntax** None mentioned in this benchmark. **Additional Considerations** When working with large datasets or performance-critical code, it's essential to consider the following factors: 1. **Browser version and compatibility**: Ensure that the chosen method works across different browsers and versions. 2. **Performance overhead**: Optimize code for performance by avoiding unnecessary functions calls or computations. 3. **Code readability**: Use clear and concise variable names, and avoid complex logic when merging objects. In conclusion, this benchmark compares the performance of three methods to merge an object with a new set of key-value pairs: ES6 spread operator, Ramda's `assoc` function, and `Object.assign()` method. The choice of method depends on personal preference, project requirements, and the need for compatibility across different browsers and versions.
Related benchmarks:
Compare the new ES6 spread operator with the traditional concat() method
Compare the new ES6 spread operator with Ramda assoc
Compare the new ES6 spread operator with Ramda assoc (v0.27.1)
Compare the new ES6 spread operator with Ramda assoc (v0.27.1) + assignment
Comments
Confirm delete:
Do you really want to delete benchmark?