Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object set vs immutable-js set vs map set
(version: 0)
Comparing performance of:
object set vs immutable-js vs map set
Created:
5 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:
object set
let obj = {}; for(i=0;i<100;i++){ const key = 'key'+i const value = 'value'+i obj[key] = value }
immutable-js
let obj = Immutable.Map(); for(i=0;i<100;i++){ const key = 'key'+i const value = 'value'+i obj = obj.set(key, {key, value}) }
map set
let obj = new Map(); for(i=0;i<100;i++){ const key = 'key'+i const value = 'value'+i obj.set(key, value) }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
object set
immutable-js
map set
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):
Measuring the performance of different approaches to set objects in JavaScript is an interesting benchmark. **What's being tested:** The provided JSON represents three test cases: 1. **Object Set**: A simple object literal is created, and then 100 keys are added using a `for` loop. The value for each key is also generated using another `for` loop. 2. **Immutable-JS Set**: The Immutable.JS library is used to create an immutable map, and then 100 entries are added using the `set()` method. 3. **Map Set**: A regular JavaScript `Map` object is created, and then 100 keys are set with values. **Options compared:** The three test cases compare the performance of different approaches: * **Object literal** (using `{}`) vs * **Immutable-JS Map** (using Immutable.JS library) * **Regular JavaScript Map** (using `Map()` constructor) **Pros and Cons:** * **Object Literal**: + Pros: Simple, widely supported, and easy to implement. + Cons: May not be optimized for performance, and can lead to slower execution times due to the overhead of dynamically creating properties on an object. * **Immutable-JS Map**: + Pros: Provides a more efficient and immutable way of working with data, which can improve performance in some cases. + Cons: Requires additional setup and imports the Immutable.JS library, adding complexity to the test code. * **Regular JavaScript Map**: + Pros: Fast and efficient, as it's implemented in native code. + Cons: May not provide the same level of immutability as Immutable-JS Map. **Library/Feature explanations:** * **Immutable-JS**: A library for working with immutable data structures. In this benchmark, it's used to create an immutable map and add entries using the `set()` method. * **`Map()` constructor**: The built-in JavaScript constructor for creating a new Map object. **Special JS feature/syntax:** There are no special JavaScript features or syntaxes used in these test cases that aren't already explained above. However, it's worth noting that the use of `let` and `const` declarations is used throughout the benchmark code. **Alternatives:** Other approaches to set objects in JavaScript could include: * Using an array-based approach, where each key-value pair is stored in an array. * Using a custom data structure, such as a trie or a binary search tree. * Utilizing WebAssembly (WASM) or another low-level language for improved performance. It's worth noting that the choice of implementation depends on the specific requirements and constraints of the project. The benchmark results provided may not be representative of all scenarios or use cases.
Related benchmarks:
Immutable.Set Union vs Constructing a new plain JS Set
Immutable.Set Union vs Constructing a new plain JS Set - small
immutable vs Native Javascript Map With Read
object spread vs immutable-js set vs native Map vs object
Comments
Confirm delete:
Do you really want to delete benchmark?