Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Compare the new ES6 spread operator with Ramda assoc
(version: 0)
Comparing performance of:
spread operator vs Ramda assoc
Created:
8 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 };
Tests:
spread operator
var result = { ...params, "c": 3 };
Ramda assoc
var result = R.assoc("c", 3, params);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
spread operator
Ramda assoc
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
spread operator
65856804.0 Ops/sec
Ramda assoc
28290578.0 Ops/sec
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark compares the performance of two methods for merging objects in JavaScript: **1. Spread Operator (`...params`):** This method uses the ES6 spread operator to create a new object that includes all properties from `params`, plus an additional property `c` with the value 3. **Pros:** * Concise and readable syntax. * Built-in to modern JavaScript. **Cons:** * Can be less performant than Ramda's specialized functions for large objects. **2. Ramda `assoc` Function:** This method uses the `R.assoc()` function from the Ramda library to create a new object that merges `params` with the property `c` having the value 3. **Pros:** * Optimized for performance, especially with large objects. * Immutability by default (objects are not modified in place). **Cons:** * Requires an external library (Ramda). * Syntax can be less intuitive than the spread operator. **Alternatives:** * **Object.assign()**: A built-in JavaScript method that merges multiple objects into a new object. It's often a good middle ground between performance and simplicity. * **lodash `merge` function**: Similar to Ramda, but from the Lodash library. Offers more advanced merging options. The benchmark results show that the spread operator is significantly faster than the Ramda `assoc` function in this particular case. However, it's important to remember that performance can vary depending on factors such as object size and complexity.
Related benchmarks:
Compare the new ES6 spread operator with the traditional concat() method
Compare the new ES6 spread operator with Ramda assoc (10000000 keys)
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?