Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
immutable objects
(version: 0)
Comparing performance of:
spread vs immutable vs mori
Created:
6 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> <script src="https://cdn.jsdelivr.net/npm/mori@0.3.2/mori.min.js"></script>
Script Preparation code:
window.keys = []; for(i=0;i<100;i++) { keys.push('value' + Math.random()) }
Tests:
spread
let obj = {}; for(i=0;i<100;i++){ const key = window.keys[i] const value = 'value'+i obj = {...obj, [key]: {key, value}} }
immutable
let obj = Immutable.Map(); for(i=0;i<100;i++){ const key = window.keys[i] const value = 'value'+i obj = obj.set(key, {key, value}) }
mori
let obj = mori.hashMap() for(i=0;i<100;i++){ const key = window.keys[i] const value = 'value'+i obj = mori.assoc(obj, key, { key, value }) }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
spread
immutable
mori
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 dive into the explanation of the provided benchmark. **Benchmark Definition** The benchmark is designed to test how fast different approaches can create and populate an object with key-value pairs. The benchmark definition uses a JavaScript script that prepares some variables, including an array `window.keys` containing random strings, which will be used as keys in the object being created. **Test Cases** There are three individual test cases: 1. **"spread"`**: This test case creates an object by spreading the result of an expression. In this case, it iterates over the `window.keys` array and uses the spread operator to add each key-value pair to the object. 2. **"immutable"`**: This test case uses the Immutable.js library to create a Map (similar to an object in JavaScript). It iterates over the `window.keys` array and sets each value using the `set()` method of the Map. 3. **"mori"`**: This test case uses the Mori library to create a hash map (a data structure similar to an object in JavaScript, but optimized for hash-based lookups). It iterates over the `window.keys` array and adds each key-value pair using the `assoc()` method of the hash map. **Options Compared** The benchmark is comparing three different approaches: * **"spread"`**: This approach uses the spread operator to create and populate an object. * **"immutable"`**: This approach uses Immutable.js to create a Map, which provides immutable data structures that can be efficiently updated. * **"mori"`**: This approach uses Mori library to create a hash map. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: 1. **"spread"`**: * Pros: Easy to implement, fast execution. * Cons: May not be suitable for large datasets or complex data structures, as it can lead to performance issues due to the creation of intermediate objects. 2. **"immutable"`**: * Pros: Provides immutable data structures that can be efficiently updated, which can improve code safety and performance. * Cons: Requires additional library dependencies (Immutable.js), may have a steeper learning curve. 3. **"mori"`**: * Pros: Optimized for hash-based lookups, provides efficient data structure updates. * Cons: May require more memory usage compared to other approaches. **Library Descriptions** 1. **Immutable.js**: A library that provides immutable data structures (Maps, Lists, Sets) and utilities for working with them. 2. **Mori library**: A lightweight library that provides a hash map data structure optimized for fast lookups and updates. **Special JS Feature/Syntax** The benchmark uses the spread operator (`...`) to create an object by spreading the result of an expression. This is a relatively modern JavaScript feature introduced in ECMAScript 2018 (ES10).
Related benchmarks:
object spread vs immutable-js set
immutable js initial value vs set
object spread vs immutable-js set vs object mutate
test object perfomance
Comments
Confirm delete:
Do you really want to delete benchmark?