I'm doing some sanity testing on a personal project before updating some state to use ImmutableJS. I have a small test I wrote to make sure that Immutable.List.equals
performs like I expect it should -- O(1).
https://github.com/naddeoa/immutablejs-slow-equals.git
The important part is below
function compareImmutableMany(l1, l2) {
let result = false;
for (let i = 0; i < iterations; i++) {
result = l1.equals(l2);
}
return result;
}
i1 = createImmutableList();
i2 = createImmutableList();
console.log("immutable lists are equal", compareImmutableMany(i1, i2));
The test is comparing two native js lists of size 100,000 and then two Immutable.List of size 100,000, each 1000 times. I must be missing something. I'm seeing the Immutable.List sample perform very bad relative to the native list sample.
starting
immutable lists are equal true
Seconds: 11.423
starting
normal lists are equal: true
Seconds: 0.109
You can run this locally with the following.
git clone https://github.com/naddeoa/immutablejs-slow-equals.git
cd immutablejs-slow-equals
npm i
node main.js
If I'm making a simple mistake then I'd appreciate some eyes to let me know where it is. I definitely expected this to be very fast. Especially because replacing l1.equals(l2)
with a call to l1.hashCode()
is really fast.