Skip to content

Instantly share code, notes, and snippets.

@coder-mike

coder-mike/immutablejs-vs-immer.js Secret

Last active Mar 4, 2021
Embed
What would you like to do?
Immutable.js vs Immer
import { produce, enableMapSet } from "immer";
import immutable from 'immutable';
import _perf from 'execution-time';
enableMapSet();
const perf = _perf();
const counts = [100, 1000, 10_000, 100_000, 1_000_000, 10_000_000];
for (const count of counts) {
console.log(count, 'counter');
immutableJsTest();
//immerTest();
plainTest();
function immutableJsTest() {
perf.start();
let map = immutable.Map();
for (let i = 0; i < count; i++)
map = map.set(i, i);
const results = perf.stop();
console.log('immutable.js', results.time);
}
function immerTest() {
perf.start();
let map = new Map();
for (let i = 0; i < count; i++)
map = produce(map, m => m.set(i, i));
const results = perf.stop();
console.log('immer', results.time);
}
function plainTest() {
perf.start();
let map = new Map();
for (let i = 0; i < count; i++)
map.set(i, i);
const results = perf.stop();
console.log('plain', results.time);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment