Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs ImmutableJs copy
(version: 0)
Tests adding an element to a map vs an immutable js map.
Comparing performance of:
ES vs Immutable
Created:
7 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.min.js'></script>
Script Preparation code:
function createLargeObject() { return { a: "oaishdjoghaisioghagsiohgiosdhgaioshdhgiashdhgohasdghasdiog", b: "asiohdjoghasdgioasdhiosdghasohgaoihsdhgioasdhgsdiohgsdhiog", c: "oasihdgoashdgiohasdhgasdoghsdihgohasdgsihgasdioghsdigiogga" } } var map1 = new Map(); for (i = 0; i < 10000; i++) { map1.set(i, createLargeObject()); } var map2 = Immutable.Map(map1)
Tests:
ES
map1 = Object.assign({}, map1, { 1001: createLargeObject() });
Immutable
map2 = map2.set(1001, createLargeObject());
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
ES
Immutable
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):
**Benchmark Explanation** The provided JSON represents two benchmark test cases, each designed to measure the performance of different approaches for adding an element to a data structure. **Option 1: ES (ECMAScript)** The first test case measures the performance of using `Object.assign()` to add an element to an existing object (`map1`). Specifically, it adds a new property-value pair with key `1001` and value `createLargeObject()`, where `createLargeObject()` is a function that returns a large object. **Pros:** * Wide compatibility across browsers and platforms * Simple and intuitive syntax **Cons:** * Can lead to performance issues if the object becomes too large or complex * May not be optimized for performance in some situations (e.g., when using a large number of iterations) **Option 2: ImmutableJs** The second test case measures the performance of using an immutable data structure provided by Immutable.js, specifically `Immutable.Map`. The benchmark creates two maps: one from an existing map (`map1`) and another from scratch (`map2`). It then adds a new element to both maps using `set()`. **Pros:** * Provides predictable and optimized performance for immutable data structures * Ensures thread safety and immutability **Cons:** * May require additional setup and configuration (e.g., importing Immutable.js library) * Can be slower than other approaches due to the overhead of creating immutable objects **Library: ImmutableJs** Immutable.js is a popular JavaScript library that provides an immutable data structure implementation, ensuring thread safety and predictability in performance. In this benchmark, it's used for its `Map` data structure. **Other Considerations** * Other alternatives to ES and ImmutableJs include using `Set` or other data structures, which may offer different trade-offs in terms of performance, memory usage, and compatibility. * The choice of approach ultimately depends on the specific use case, performance requirements, and personal preference. In summary, this benchmark tests the performance of two approaches for adding an element to a data structure: ES (using `Object.assign()`) and ImmutableJs (using `Immutable.Map`). Each approach has its pros and cons, which are considered in the context of the benchmark's specific use case.
Related benchmarks:
object spread vs immutable-js set vs native Map copy
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
immutable vs Native Javascript Map With Read Complex With Count New
Comments
Confirm delete:
Do you really want to delete benchmark?