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
llama3.1:latest
, generated one year ago):
Let's dive into the details of this benchmark test. **What is being tested?** The test compares two JavaScript libraries for managing complex data structures: Ramda and Immer. Specifically, it measures how fast each library can update a specific data structure in response to new data. **Data Structure** The data structure is an object called `INITIAL_DATA`, which contains several properties: * `items`: An object with 100 key-value pairs, where each key is a unique integer (`0` to `99`) and the value is another object with `id`, `name`, and `value` properties. * `array`: An array of 100 objects, similar to `items`. * `count`: A counter that increments by 1 for each new item added. * `keys`: An array of unique integers (`0` to `99`) representing the indices of the items. **Test Cases** There are two test cases: 1. **Ramda**: This test uses the Ramda library's `compose`, `over`, and `lensPath` functions to update the data structure. * The function chain creates a lens that points to the `keys` property, then appends a new item with a unique ID (`NEW_ITEM_ID`) using the `append` function from Ramda. * The resulting updated data structure is assigned to the variable `data`. 2. **Immer**: This test uses the Immer library's `produce` function to update the data structure. * The `produce` function creates a new draft of the initial data, which is then updated by adding a new item with the unique ID (`NEW_ITEM_ID`) and incrementing the counter. **Benchmark Results** The latest benchmark results show that Immer performs significantly better than Ramda on this specific test case: | Test Name | Executions Per Second | | --- | --- | | ramda | 186481.375 | | immer | 22075.26171875 | This suggests that Immer is faster for updating complex data structures like the one used in this benchmark. **Library Details** * **Ramda**: A functional programming library for JavaScript that provides a set of higher-order functions (HOFs) for tasks like data manipulation, array processing, and string manipulation. In this test case, Ramda's `compose`, `over`, and `lensPath` functions are used to create a complex function chain. * **Immer**: A library for managing complex data structures in JavaScript. Immer provides a way to create a "draft" of an existing object, which can be updated without affecting the original data. The `produce` function is used to create this draft. **Other Considerations** While this benchmark test specifically compares Ramda and Immer, there are other libraries available for managing complex data structures in JavaScript, such as Magma, Redux, and Vuex. The choice of library depends on the specific requirements of your project. In general, when working with complex data structures, consider using a library that provides a more functional programming approach (like Ramda or Immer) to make it easier to reason about and manage your code. However, if you're already invested in an object-oriented programming style, libraries like Redux or Vuex might be a better fit. Hope this explanation helps!
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?