Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Immerjs vs Immutable Perf Test
(version: 0)
Comparing performance of:
immer vs Immutable
Created:
6 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/immer/dist/immer.umd.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.js"></script>
Script Preparation code:
//const { fromJS } = require('immutable'); var data = { items: {}, count: 0, keys: [] } for (let index = 0; index < 100; index++) { data[index] = { id: index, name: `ITEM-${index}`, value: Math.random() } data.count++ data.keys.push(index) } var NEW_ITEM_ID = data.count +1 var produce = immer.default var im = Immutable.fromJS(data);
Tests:
immer
data = produce(data, draft => { draft.items[NEW_ITEM_ID] = { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 } draft.counter++ draft.keys.push(NEW_ITEM_ID) })
Immutable
var im = Immutable.fromJS(data); im = im.set('items', im.get('items').set(NEW_ITEM_ID, { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 })); im = im.set('count', im.count +1); im = im.set('keys', im.get('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
immer
Immutable
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
immer
1666.7 Ops/sec
Immutable
1336.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring the performance of two popular JavaScript libraries for immutability testing, Immer and Immutable. **What is being tested?** In this benchmark, the focus is on comparing the performance of two libraries, Immer and Immutable, when it comes to creating and manipulating immutable data structures. Specifically, the benchmark measures how quickly each library can update a dataset by adding a new item with some predefined properties. **Options compared:** 1. **Immer**: A lightweight, incremental update approach for immutability. It uses an in-memory draft object that's updated incrementally, allowing for faster updates. 2. **Immutable**: A full-fledged immutable library that creates a new copy of the original data structure whenever it needs to be updated. **Pros and Cons:** 1. **Immer**: * Pros: + Faster performance due to incremental updates + More efficient memory usage, as no new copies are created * Cons: + May not provide a complete, isolated update (draft object is still in memory) 2. **Immutable**: * Pros: + Provides a completely isolated and predictable update behavior + Suitable for use cases where data safety is critical * Cons: + Slower performance due to creating new copies of the original data structure **Library descriptions:** 1. **Immer**: A lightweight, incremental update library developed by Facebook. It's designed to provide fast and efficient updates while maintaining immutability. 2. **Immutable**: A full-fledged immutable library for JavaScript, developed by Facebook. It provides a complete and predictable way of handling immutable data structures. **Special JS features:** In this benchmark, the following special JS feature is used: 1. **Async/await syntax**: The `im.set` method in Immutable's example uses async/await syntax to wait for the previous update operation to complete before executing the next one. **Other considerations:** When choosing between Immer and Immutable, consider the trade-offs between performance, memory usage, and data safety: * If you prioritize fast updates and efficient memory usage, Immer might be a better choice. * If you require a completely isolated and predictable update behavior, Immutable is likely a better fit. **Alternatives:** Other alternatives to Immer and Immutable include: 1. **Lodash**: A popular utility library that includes functions for manipulating immutable data structures. 2. **MochaJS**: A lightweight JavaScript object that provides a similar interface to Immutable's `fromJS` method. 3. **JS-Immutables**: A lightweight, incremental update library inspired by Immer. Note: This list is not exhaustive and other libraries or alternatives might be suitable for specific use cases.
Related benchmarks:
Immerjs vs Shallow copy vs Immutable Perf Test
Immer vs Shallow copy vs Immutable Perf Test 3 (update library version)
Immer vs Shallow copy vs Immutable Perf Test copy
Immer vs Shallow copy vs Immutable Perf Test updated
Comments
Confirm delete:
Do you really want to delete benchmark?