Immutable.js vs Immer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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