HTML Preparation code:
AخA
 
1
<script src="https://unpkg.com/immer/dist/immer.umd.js"></script>
2
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.js"></script>
Script Preparation code:
x
 
//const { fromJS } = require('immutable');
var data = { items: {}, count: 0, keys: [] }
for (let index = 0; index < 100; index++) {
  data[index] = { id: index, name: `ITEM-${index}`, value: Math.random() }
  data.count++
  data.keys.push(index)
}
var NEW_ITEM_ID = data.count +1
var produce = immer.default
var im = Immutable.fromJS(data);
Tests:
  • immer

     
    data = produce(data, draft => {
      draft.items[NEW_ITEM_ID] = { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 }
      draft.counter++
      draft.keys.push(NEW_ITEM_ID)
    })
  • shallow copy

     
    data = {
      ...data,
      items: {
        ...data.items,
        [NEW_ITEM_ID]: { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 }
      },
      count: data.count +1,
      keys: [ ...data.keys, NEW_ITEM_ID]
    }
  • Immutable

     
    var im = Immutable.fromJS(data);
    im = im.set('items', im.get('items').set(NEW_ITEM_ID, { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 }));
    im = im.set('count', im.count +1);
    im = im.set('keys', im.get('keys').push(NEW_ITEM_ID));
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    immer
    shallow copy
    Immutable

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
Chrome 79 on Mac OS X 10.15.3
View result in a separate tab
Test name Executions per second
immer 1574.7 Ops/sec
shallow copy 3875.8 Ops/sec
Immutable 66.6 Ops/sec