Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Immer v Ramda v Splat
(version: 0)
Comparing performance of:
immer vs shallow copy vs ramda lens
Created:
6 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://unpkg.com/immer"></script> <script src="https://unpkg.com/ramda"></script>
Script Preparation code:
var { compose, over, set, lensPath, append } = R var INITIAL_DATA = { items: {}, count: 0, keys: [] } for (var index = 0; index < 100; index++) { INITIAL_DATA[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:
immer
data = produce(INITIAL_DATA, draft => { draft.items[NEW_ITEM_ID] = { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 } draft.counter++ draft.keys.push(NEW_ITEM_ID) })
shallow copy
data = { ...INITIAL_DATA, items: { ...INITIAL_DATA.items, [NEW_ITEM_ID]: { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 } }, count: INITIAL_DATA.count +1, keys: [ ...INITIAL_DATA.keys, NEW_ITEM_ID] }
ramda lens
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 }) )(INITIAL_DATA);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
immer
shallow copy
ramda lens
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.2:3b
, generated one year ago):
**What is being tested?** The provided benchmark tests three different approaches to update and modify an object's structure: 1. **Immer**: A library that provides a simple, mutable way to work with immutable objects. It creates a new copy of the original object and updates it in-place. 2. **Shallow Copy**: A manual approach to creating a new copy of the object by spreading its properties into a new object. 3. **Ramda Lens**: A functional programming library that provides a way to update specific parts of an object using functions. **Options compared** The benchmark compares the performance of these three approaches: * Immer: Uses the `immer` library to create a new copy of the object and updates it in-place. * Shallow Copy: Manually creates a new copy of the object by spreading its properties into a new object. * Ramda Lens: Uses Ramda's `lensPath` and `over` functions to update specific parts of the object. **Pros and Cons** 1. **Immer**: * Pros: Simple, readable code, efficient updates in-place. * Cons: May have higher memory overhead due to creating multiple copies of the original object. 2. **Shallow Copy**: * Pros: No additional libraries required, simple code. * Cons: Manual code can be error-prone and less readable than using a library like Immer. 3. **Ramda Lens**: * Pros: Functional programming style provides elegant and composable updates to objects. * Cons: May have higher overhead due to creating multiple function calls and data structures. **Library used - Ramda** Ramda is a functional programming library for JavaScript that provides a set of functions for manipulating and transforming data. In this benchmark, Ramda's `lensPath` and `over` functions are used to update specific parts of the object. The `lensPath` function takes an array of strings representing the path to the value to be updated, while the `over` function applies a transformation function to the value at that path. **Special JS feature - None** There is no special JavaScript feature or syntax being tested in this benchmark. **Other alternatives** If you're looking for alternative libraries or approaches, consider: 1. **Lodash**: A popular utility library that provides a `cloneDeep` function for creating deep copies of objects. 2. **Mongose**: A MongoDB object modeling library that includes functions for updating and modifying documents. 3. **Immutable.js**: Another immutable data structure library that provides similar functionality to Immer. Keep in mind that the best approach will depend on your specific use case, performance requirements, and personal preference.
Related benchmarks:
Immer vs shallow vs ramda lens
Immer vs shallow vs ramda lens by d
Immer vs shallow vs ramda lens (2)
ramda vs immer with fixed setup
Comments
Confirm delete:
Do you really want to delete benchmark?