Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Immer freeze comparison2
(version: 0)
Comparing performance of:
immer no freeze vs immer freeze
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://unpkg.com/immer@9/dist/immer.umd.production.min.js"></script>
Script Preparation code:
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 im = immer;
Tests:
immer no freeze
im.setAutoFreeze(false) var produce = im.default 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) })
immer freeze
im.setAutoFreeze(true) var produce = im.default 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) })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
immer no freeze
immer freeze
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):
Let's break down the benchmark definition and test cases to understand what is being tested. **Benchmark Definition** The benchmark definition is represented by a JSON object that describes two test cases: 1. **Immer Freeze Comparison**: The script preparation code initializes an object `INITIAL_DATA` with 100 properties, each containing an ID, name, and value. It also defines a new item ID `NEW_ITEM_ID`. 2. **Html Preparation Code**: This section includes the HTML code that loads the Immer library (version 9) via a CDN. 3. **Individual Test Cases**: There are two test cases: * **Immer No Freeze**: The script preparation code sets `im.setAutoFreeze(false)` and then creates a draft of the initial data using the `immer.default` function. The draft is modified to add a new item with ID `NEW_ITEM_ID`. * **Immer Freeze**: This test case is similar to the previous one, but it sets `im.setAutoFreeze(true)`, which enables automatic freezing of the draft. **What is being tested?** The benchmark is testing the performance difference between two Immer configurations: 1. **No Freeze**: When `im.setAutoFreeze(false)`, the draft must be manually frozen before using it. 2. **Freeze**: When `im.setAutoFreeze(true)`, the draft is automatically frozen, which may reduce memory allocation and garbage collection overhead. **Pros and Cons of each approach** * **No Freeze (immer.setAutoFreeze(false))**: + Pros: More control over the draft, allows for manual freezing to improve performance in certain scenarios. + Cons: Requires more code and can lead to increased memory allocation and garbage collection overhead due to frequent freezing and thawing. * **Freeze (immer.setAutoFreeze(true))**: + Pros: Reduces memory allocation and garbage collection overhead by automatically freezing the draft. + Cons: May limit control over the draft, as the automatic freezing process can introduce performance bottlenecks. **Library: Immer** Immer is a JavaScript library that provides a simple and efficient way to work with immutable data structures. It's designed to simplify state management in functional programming languages. In this benchmark, Immer is used to create drafts of the initial data, which are then modified and compared for performance differences. **Special JS feature or syntax** There isn't any specific JavaScript feature or syntax mentioned in the benchmark definition that requires special attention. However, it's worth noting that the use of `immer.default` and `im.setAutoFreeze()` suggests that the author is familiar with the Immer library and its features. **Other alternatives** If you're looking for alternative libraries to compare with Immer, some options might include: 1. **Lodash immutables**: A small subset of Lodash's functions that work with immutable data structures. 2. **Mocha**: A popular testing framework that can be used in conjunction with other libraries like Immer or Lodash immutables. 3. **Benchmarking libraries**: Such as Benchmark.js, which provides a simple way to create and run benchmarks. Keep in mind that the choice of alternative library will depend on your specific use case and requirements.
Related benchmarks:
Immer vs shallow copy
Immer vs shallow copy222ddd
Immer vs shallow copy222dddxxx
Immer & Immutable benchmarks with inceremntal data
Comments
Confirm delete:
Do you really want to delete benchmark?