Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
POJOs vs Immutables
(version: 1)
Comparing performance of:
Pojos array Insert vs List with pojos Insert vs List with records Insert
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/4.1.0/immutable.min.js" integrity="sha512-OQDhbg3GkxL1XYlKM3zUzP9fYbL93uBQU6fsSl0tpr5aUp1CV3AI7hMgMVJqlCy63ppR5Ff/pk68ZjPAOjIgiQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Script Preparation code:
var numElements = 1000000; var FooRecord = Immutable.Record({ foo: null }); var pojosArray = []; var listWithPojos = Immutable.List([]); var listWithRecords = Immutable.List([]); for (let i = 0; i < numElements; i++) { pojosArray.push({ foo: 'bar' }); listWithPojos = listWithPojos.push({ foo: 'bar' }); listWithRecords = listWithRecords.push(FooRecord({ foo: 'bar' })); }
Tests:
Pojos array Insert
[...pojosArray.slice(0, numElements / 2), { foo: 'bar' }, ...pojosArray.slice(numElements / 2)]
List with pojos Insert
listWithPojos.insert(numElements / 2, { foo: 'bar' });
List with records Insert
listWithRecords.insert(numElements / 2, FooRecord({ foo: 'bar' }));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Pojos array Insert
List with pojos Insert
List with records Insert
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's being tested. **Overview** The benchmark measures the performance of three different data structures: POJOs (Plain Old JavaScript Objects) arrays, Immutable Lists with POJOs, and Immutable Records with POJOs. The test creates large datasets and performs operations on them to compare the performance of each data structure. **Data Structures** 1. **POJOs Arrays**: A plain array of objects, where each object has a single property `foo` initialized with the value `'bar'`. 2. **Immutable Lists with POJOs**: An Immutable List (from the Immutable library) that holds POJOs arrays. 3. **Immutable Records with POJOs**: An Immutable Record (from the Immutable library) that holds POJOs. **Test Cases** The benchmark consists of three test cases: 1. **Pojos array Insert**: The test creates a large POjos array, takes half of it, and then inserts a new element at the middle index. 2. **List with pojos Insert**: The test creates an Immutable List with POjos arrays and inserts a new element at the middle index. 3. **List with records Insert**: The test creates an Immutable Record with POJOs and inserts a new element at the middle index. **Library Used** The Immutable library is used for working with Immutable Lists and Records. Immutable provides a way to create data structures that are immutable by design, which can lead to better performance and easier debugging. **Special JS Features/Syntax** There's no specific JavaScript feature or syntax being tested in this benchmark. **Pros and Cons of Each Approach** 1. **POJOs Arrays**: Pros: * Easy to implement and understand. * Fast insertion times due to array's contiguous nature. Cons: * Not designed for immutability, which can lead to performance issues if not handled correctly. 2. **Immutable Lists with POJOs**: Pros: + Immutable by design, reducing the risk of unintended side effects. + Can be more efficient than mutable arrays for large datasets. Cons: + Requires an additional library (Immutable) and setup. 3. **Immutable Records with POJOs**: Pros: + Provides a way to create immutable data structures that are also easy to understand and work with. Cons: + May have performance overhead due to the creation of new objects. **Other Alternatives** If you're looking for alternative data structures or libraries, here are some options: 1. **Memento**: A library that provides a similar concept to Immutable Records, but with a different implementation. 2. **MapReduce**: A JavaScript library that provides a way to work with immutable data structures and perform common operations like filtering and mapping. 3. **Array.prototype.reduceRight()**: A built-in JavaScript method that can be used for iterative operations on arrays. Keep in mind that each alternative has its own strengths and weaknesses, and the choice ultimately depends on your specific use case and requirements.
Related benchmarks:
toArray vs toJS
Immutable Map vs Ordered Map vs List
Spread operator vs Immutable.js performance for common use cases
POJOs vs Immutable Maps
Comments
Confirm delete:
Do you really want to delete benchmark?