<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.min.js'></script>
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);
var result = testImmutable.toJS();
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'),
};
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Immutable toJS | |
Immutable get |
Test name | Executions per second |
---|---|
Immutable toJS | 711100.1 Ops/sec |
Immutable get | 747645.7 Ops/sec |
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:
testObj
) using the Immutable.fromJS()
method. It then calls the toJS()
method on the resulting Immutable.js object and measures its execution time.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:
toJS()
: This method converts an Immutable.js object back into a plain JavaScript object, allowing direct access to its properties.get()
: This method allows accessing individual properties of an Immutable.js object without converting it to a plain JavaScript object.Pros and Cons
toJS()
:get()
: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.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.