Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test Immutable ToJS vs get
(version: 0)
Comparing performance of:
Immutable toJS vs Immutable get
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:
var testObj = { item1: '1234', item2: '1234', item3: '1234', item4: '1234', item5: '1234', item6: '1234', item7: '1234', item8: '1234', item9: '1234', item10: '1234', item11: '1234', item12: '1234', item13: '1234', item14: '1234', item15: '1234', item16: '1234', item17: '1234', item18: '1234', item19: '1234', item20: '1234', item21: '1234', item22: '1234', item23: '1234', }; var testImmutable = Immutable.fromJS(testObj);
Tests:
Immutable toJS
var result = testImmutable.toJS();
Immutable get
var testObj = { item1: testImmutable.get('item1'), item2: testImmutable.get('item2'), item3: testImmutable.get('item3'), item4: testImmutable.get('item4'), item5: testImmutable.get('item5'), item6: testImmutable.get('item6'), item7: testImmutable.get('item7'), item8: testImmutable.get('item8'), item9: testImmutable.get('item9'), item10: testImmutable.get('item10'), item11: testImmutable.get('item11'), item12: testImmutable.get('item12'), item13: testImmutable.get('item13'), item14: testImmutable.get('item14'), item15: testImmutable.get('item15'), item16: testImmutable.get('item16'), item17: testImmutable.get('item17'), item18: testImmutable.get('item18'), item19: testImmutable.get('item19'), item20: testImmutable.get('item20'), item21: testImmutable.get('item21'), item22: testImmutable.get('item22'), item23: testImmutable.get('item23'), };
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Immutable toJS
Immutable get
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Immutable toJS
711100.1 Ops/sec
Immutable get
747645.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The provided JSON represents a JavaScript microbenchmark created on MeasureThat.net. The benchmark compares the performance of two approaches for accessing data in an Immutable.js object: `toJS()` and `get()`. The goal is to determine which approach is faster. **What is tested?** In this benchmark, we have two test cases: 1. **Immutable toJS**: This test case creates an Immutable.js object from a JavaScript object (`testObj`) using the `Immutable.fromJS()` method. It then calls the `toJS()` method on the resulting Immutable.js object and measures its execution time. 2. **Immutable get**: This test case creates the same Immutable.js object as above, but instead of calling `toJS()`, it uses the `get()` method to access individual properties of the object (e.g., `testImmutable.get('item1')`). It then measures the total number of executions per second for all property accesses. **Options compared** The two options being compared are: 1. **`toJS()`**: This method converts an Immutable.js object back into a plain JavaScript object, allowing direct access to its properties. 2. **`get()`**: This method allows accessing individual properties of an Immutable.js object without converting it to a plain JavaScript object. **Pros and Cons** * **`toJS()`**: + Pros: Allows direct access to Immutable.js object properties using familiar JavaScript syntax. Can be faster if most accesses are sequential. + Cons: Converts the entire Immutable.js object, which can be costly in terms of memory and performance. * **`get()`**: + Pros: Does not convert the entire Immutable.js object, which can reduce memory usage and improve performance for large datasets or frequent access patterns. Can be faster for random access patterns. + Cons: Requires more complex syntax to access individual properties. **Library used** The Immutable.js library is used in this benchmark to create immutable objects and provide the `toJS()` and `get()` methods. **Special JS feature or syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. The focus is on comparing the performance of two different approaches for accessing data in an Immutable.js object. **Other alternatives** If you wanted to compare other approaches, here are some potential alternatives: * **`map()` and `forEach()`**: These methods can be used to iterate over the properties of an Immutable.js object. This approach might offer a balance between direct access and conversion-free performance. * **`filter()`**: Similar to `map()` and `forEach()`, this method can be used to filter or transform properties in an Immutable.js object. * **Other libraries or implementations**: Depending on your specific requirements, you might want to explore other JavaScript libraries or implementations that provide similar functionality to Immutable.js. Keep in mind that the performance differences between these alternatives will depend on the specific use case and dataset. It's essential to consider factors like memory usage, access patterns, and dataset size when choosing an approach.
Related benchmarks:
toArray vs toJS
immutable vs lodash vs ... 3
immutable vs lodash vs ... 4
immutable vs lodash vs ... 5
Immutable toJS vs set
Comments
Confirm delete:
Do you really want to delete benchmark?