Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object assign vs object spread vs immutable-js vs immutability-helper on large data set 2
(version: 0)
Comparing performance of:
object spread vs object assign vs immutable-js
Created:
7 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 spread
const obj = {}; for(i=0;i<100000;i++){ obj[i] = 'some long string which will need to be copied'; } const obj2 = {key: 'This is final object'} const final = {obj2, ...obj};
object assign
const obj = {}; for(i=0;i<100000;i++){ obj[i] = 'some long string which will need to be copied'; } const obj2 = {key: 'This is final object'} const final = Object.assign({}, obj2, obj)
immutable-js
const obj = {}; for(i=0;i<100000;i++){ obj[i] = 'some long string which will need to be copied'; } const immObj = Immutable.Map(); const obj2 = {key: 'This is final object'} const final = immObj.set(obj).set(obj2);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
object spread
object assign
immutable-js
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):
**Overview of the Benchmark** The provided JSON represents a JavaScript microbenchmarking test, specifically designed to compare the performance of three different approaches for object assignment: 1. Object spread (`...` operator) 2. Object assign (`Object.assign()` method) 3. Immutable.js library (specifically, `Immutable.Map().set()` method) **Benchmark Preparation Code** The script preparation code includes two external libraries: * Immutable.js: a library for immutable data structures and operations. * Immutability-helper: a utility library that provides helper functions for working with immutable data. The benchmark preparation code is minimal and only sets up the necessary environment for the test cases to run. It defines an empty object `obj` and another object `obj2`, which will be used as input data for each test case. **Individual Test Cases** Each test case has a unique name and a benchmark definition that describes how the assignment should be performed: 1. **Object Spread**: The assignment is done using the spread operator (`...`) to merge two objects: `final` and `obj`. 2. **Object Assign**: The assignment is done using the `Object.assign()` method to merge two objects: `final` and `obj`. 3. **Immutable.js**: The assignment is done using the `Immutable.Map().set()` method, which creates a new immutable map and sets two properties on it. **Comparison of Options** Here's a brief overview of each approach: * **Object Spread**: This method is concise and efficient but may be slower than other methods due to the creation of a new object. + Pros: Easy to read and write, fast performance. + Cons: May create unnecessary objects in memory. * **Object Assign**: This method is widely supported and has good performance but can be slower than the spread operator for large datasets. + Pros: Widespread support, fast performance. + Cons: Can be slower for large datasets, may have issues with object size limits. * **Immutable.js**: This method provides a more functional programming approach to assignment and is well-suited for immutable data structures. + Pros: Provides immutability, easy to use in functional programming contexts. + Cons: May be overkill for simple assignments, slower performance. **Special JS Features** There are no special JavaScript features or syntax used in this benchmark. The focus is on the assignment methods themselves. **Other Alternatives** If you're looking for alternative methods, consider: * **Array.prototype.push()**: Assigning to an array's `push()` method can be faster than object assign. * **Set.add()**: Assigning to a Set using the `add()` method can be faster than object assign. * **Function calls with objects as arguments**: Passing objects as arguments to functions can be faster than assigning to properties. Keep in mind that these alternatives may not be suitable for all use cases and might require additional setup or configuration.
Related benchmarks:
object assign vs object spread vs immutable-js vs immutability-helper on large data set
object assign vs object spread vs immutable-js vs immutability-helper on large data set 3
object assign vs object spread vs immutable-js vs immutability-helper on large data set - z
Spread operator vs Immutable.js performance for common use cases
Comments
Confirm delete:
Do you really want to delete benchmark?