Skip to content

Instantly share code, notes, and snippets.

@coder-mike
Last active March 4, 2021 20:54
Show Gist options
  • Save coder-mike/2341d5555f58623be49d66e0a6a52ae8 to your computer and use it in GitHub Desktop.
Save coder-mike/2341d5555f58623be49d66e0a6a52ae8 to your computer and use it in GitHub Desktop.
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