Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
immutable vs Native Javascript Map
(version: 0)
immutable vs Native Javascript Map
Comparing performance of:
immutable Map vs Native Javascript Map
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/immutability-helper@2.7.0/index.min.js"></script>
Tests:
immutable Map
let obj = Immutable.Map(); for(i=0;i<10000;i++){ const key = 'key'+i const value = 'value'+i obj.set(key, {key, value}) }
Native Javascript Map
let obj = new Map(); for(i=0;i<10000;i++){ const key = 'key'+i const value = 'value'+i obj.set(key, {key, value}) }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
immutable Map
Native Javascript Map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Android 12; Mobile; rv:149.0) Gecko/149.0 Firefox/149.0
Browser/OS:
Firefox Mobile 149 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
immutable Map
634.5 Ops/sec
Native Javascript Map
276.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested. **Benchmark Definition** The benchmark compares two approaches to creating an immutable data structure in JavaScript: Immutable.js maps and native JavaScript Maps. **Immutable vs Native Javascript Map** * **Immutable.js Map**: An immutable map is a data structure that cannot be modified after creation. In this benchmark, we create an empty immutable map using `Immutable.Map()` and then add 10,000 key-value pairs to it using the `set()` method. We repeat this process multiple times. * **Native Javascript Map**: A native JavaScript Map is a built-in data structure that can be modified after creation. In this benchmark, we create an empty native map using `new Map()` and then add 10,000 key-value pairs to it using the `set()` method. We repeat this process multiple times. **Options Compared** The two options being compared are: * Immutable.js maps: Pros: * Immutability ensures data integrity and makes it easier to reason about code. * Immutable.js provides a range of useful utilities for working with immutable data structures. * Native JavaScript Maps: Cons: * Immutability is not enforced, which can lead to bugs or incorrect behavior if data is modified accidentally. * Native maps are optimized for performance and may have better cache locality than immutable maps. * Pros: * Faster execution speed due to native optimization. * Better cache locality. **Library Used** The benchmark uses two libraries: 1. **Immutable.js**: A JavaScript library that provides a range of utilities for working with immutable data structures, including maps, lists, and sets. 2. **Immutability-helper**: A small library that provides additional utility functions for working with immutable data structures. **Special JS Feature or Syntax** The benchmark uses the `set()` method to add key-value pairs to both types of maps. The `set()` method is a standard part of JavaScript, and its usage is not specific to any particular feature or syntax. **Other Considerations** When choosing between an immutable map and a native map, consider the following factors: * Data integrity: If immutability is crucial for your application, use an immutable map. Otherwise, native maps may be sufficient. * Performance: Native maps are optimized for performance, so if execution speed is critical, choose a native map. **Alternatives** Other alternatives to Immutable.js and native JavaScript Maps include: 1. **Lodash**: A utility library that provides functions for working with arrays, objects, and other data structures. 2. **Ramda**: A functional programming library that provides a range of utility functions for working with immutable data structures. 3. **JSMap**: A JavaScript library that provides a range of features for working with native maps, including utilities for mapping and reducing. These alternatives may offer different trade-offs in terms of performance, functionality, and complexity, so be sure to evaluate them carefully before making a decision.
Related benchmarks:
Immutable.Set Union vs Constructing a new plain JS Set
immutable vs Native Javascript Map With Read
immutable vs Native Javascript Map With Read Complex
immutable vs Native Javascript Map With Read Complex With Count
Comments
Confirm delete:
Do you really want to delete benchmark?