Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Filter state 1000000 elements
(version: 6)
Comparing performance of:
Plain JS vs Immutable vs Immutable Deep
Created:
7 years ago
by:
Registered User
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 Preparation code:
arr = []; for(i=0;i<1000000;i++){ arr.push({ id: i, text: 'some long string which will need to be copied' }) } immuObj = Immutable.Set(arr) immuObj2 = Immutable.fromJS(arr)
Tests:
Plain JS
const final = arr.filter(val => val.id === 654321)
Immutable
const final = immuObj.filter(val => val.id === 654321)
Immutable Deep
const final = immuObj2.filter(val => val.get('id') === 654321)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Plain JS
Immutable
Immutable Deep
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 provided benchmark and explain what is being tested. **Benchmark Definition** The benchmark is designed to measure the performance of two approaches: plain JavaScript (JS) and two variants of Immutable.js, which is a library for functional programming in JavaScript. **Script Preparation Code** The script preparation code generates an array of 1 million objects with `id` and `text` properties. This data structure will be used to test the filtering capabilities of each approach. **Html Preparation Code** The HTML preparation code includes a script tag that loads the Immutable.js library, version 3.8.2, which is used by the second two benchmark definitions. **Individual Test Cases** There are three individual test cases: 1. **Plain JS**: This test case uses plain JavaScript to filter the array using the `filter()` method. 2. **Immutable**: This test case uses the Immutable.js library to create a set from the prepared array and then filters it using the `filter()` method. 3. **Immutable Deep**: This test case is similar to the "Immutable" test case, but instead of using an array, it uses an Immutable.js object (`immuObj2`) that wraps the original array data structure. **Options Compared** The three test cases compare two approaches: * Plain JavaScript (JS) vs. Immutable.js (with set) * Plain JavaScript (JS) vs. Immutable.js with deep access to properties (via `get()`) **Pros and Cons of Each Approach** 1. **Plain JS**: This approach is simple and easy to understand, but it can be slow for large datasets due to the overhead of iterating over the entire array. 2. **Immutable**: Using an immutable data structure can provide better performance and thread-safety, as it eliminates the need to mutate the original data. However, creating a set from an array can be computationally expensive. 3. **Immutable Deep**: This approach provides similar benefits to Immutable.js but with deeper access to properties, which may be necessary for certain use cases. **Library: Immutable.js** Immutable.js is a library that provides functional programming utilities and data structures, including sets, maps, lists, and more. Its primary purpose is to help developers write predictable and efficient code by abstracting away mutable state and providing immutable data structures. In the context of this benchmark, Immutable.js is used to create an immutable set from the prepared array, which allows for faster filtering operations without modifying the original data structure. **Special JS Features or Syntax** None mentioned in this explanation. However, note that using Immutable.js may require some knowledge of functional programming concepts, such as immutability and higher-order functions. **Other Alternatives** If you're interested in exploring alternative approaches to benchmarking JavaScript performance, consider: * Using other libraries like Lodash or Underscore.js for functional programming utilities. * Implementing custom data structures or algorithms for filtering operations. * Comparing performance using different browser versions, platforms, or devices.
Related benchmarks:
Immutable vs Native
set-immutablejs-vs-plain
object spread vs immutable-js corrected
object spread vs immutable-js corrected v2
Comments
Confirm delete:
Do you really want to delete benchmark?