Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ramda vs immer with fixed setup
(version: 0)
Comparing performance of:
ramda vs immer
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://unpkg.com/immer"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
Script Preparation code:
var { compose, over, set, lensPath, append } = R var INITIAL_DATA = { items: {}, array: [], count: 0, keys: [] } for (var index = 0; index < 100; index++) { INITIAL_DATA.items[index] = { id: index, name: `ITEM-${index}`, value: Math.random() } INITIAL_DATA.array[index] = { id: index, name: `ITEM-${index}`, value: Math.random() } INITIAL_DATA.count++ INITIAL_DATA.keys.push(index) } var NEW_ITEM_ID = INITIAL_DATA.count +1 var produce = immer.default
Tests:
ramda
data = compose( over(lensPath(["keys"]), append(NEW_ITEM_ID)), over(lensPath(["count"]), x => x + 1), set(lensPath(["items", NEW_ITEM_ID]), { id: NEW_ITEM_ID, name: "ITEM-NEW", value: 0 }), set(lensPath(["array", NEW_ITEM_ID]), { id: NEW_ITEM_ID, name: "ITEM-NEW", value: 0 }) )(INITIAL_DATA);
immer
data = produce(INITIAL_DATA, draft => { draft.items[NEW_ITEM_ID] = { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 } draft.array[NEW_ITEM_ID] = { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 } draft.counter++ draft.keys.push(NEW_ITEM_ID) })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
ramda
immer
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark tests the performance of two libraries for updating object structures in JavaScript: Ramda and Immer. **Here's a breakdown:** * **Scenario:** Both libraries are used to modify a pre-existing data structure (`INITIAL_DATA`) by adding a new item with specific properties (`id`, `name`, `value`) and updating counters and arrays. * **Ramda approach:** * Uses functional composition (`compose`) to chain together several functions: * `over`: Modifies nested properties (like `keys` array and `count`) using lensPath for precise targeting. * `set`: Directly assigns new values to specific properties in the `items` and `array` objects based on an index. * **Pros:** Declarative style, potentially reusable functions. * **Cons:** Can be verbose for complex updates, requires understanding of functional concepts like lensPath. * **Immer approach:** * Uses a `produce` function that takes the initial data and a callback function (`draft => ...`). * Inside the callback, you directly modify the `draft` object (which is a copy) using dot notation or bracket notation. Changes are automatically tracked and applied to the original data structure when `produce` returns. * **Pros:** More intuitive syntax for beginners, avoids mutating the original data directly. * **Cons:** Might not be as readable for complex updates compared to functional programming style. **Other Considerations:** * **Libraries:** * Ramda: A powerful library focused on functional programming paradigms in JavaScript. * Immer: Specifically designed for managing state changes immutably and efficiently, often used with Redux-like libraries. * **Alternatives:** There are other approaches to updating objects in JavaScript besides these libraries: * Using object destructuring and spreading (for simpler updates). * Creating new objects by copying properties and modifying them (less efficient for large data structures). **Conclusion:** This benchmark highlights the performance difference between Ramda and Immer, with Immer generally being faster in this specific scenario. The best choice depends on your project's needs, team familiarity with functional programming, and complexity of updates.
Related benchmarks:
Immer vs shallow vs ramda lens
Immer (setAutoFreeze(false)) vs shallow vs ramda lens vs immutabe js vs immutable js (toJS) vs mutating 2.0
Immer vs shallow vs ramda lens (2)
Immer (setAutoFreeze(false)) vs shallow vs ramda lens vs samless immutable111 2
Comments
Confirm delete:
Do you really want to delete benchmark?