Skip to content

Instantly share code, notes, and snippets.

@pablolmiranda
Last active September 15, 2016 07:22
Show Gist options
  • Save pablolmiranda/b7b9a5f43d7a8a003b0c1d007c667787 to your computer and use it in GitHub Desktop.
Save pablolmiranda/b7b9a5f43d7a8a003b0c1d007c667787 to your computer and use it in GitHub Desktop.
Immutable vs. Seamless-Immutable benchmark tests
var Benchmark = require('benchmark');
var Immutable = require('immutable');
var lodash = require('lodash');
var SeamlessImmutable = require('seamless-immutable');
var arr = [];
for (var i = 0; i < 200; i++) {
arr.push({
index: i,
name: 'Pittsburgh Pirates',
id: 'mlb.t.1',
url: 'https://sports.yahoo.com/mlb/team/pit'
});
}
var obj = {
index: 50,
name: 'Pittsburgh Pirates',
id: 'mlb.t.1',
url: 'https://sports.yahoo.com/mlb/team/pit',
data: {
foo: 'bar'
}
};
var list = Immutable.fromJS(arr);
var map = Immutable.fromJS(obj);
var siList = SeamlessImmutable(arr);
var siMap = SeamlessImmutable(obj);
var suite = new Benchmark.Suite;
suite.add('JS property set', function() {
arr[51].index = 52;
})
.add('lodash.set (deep)', function () {
lodash.set(arr, [52, 'index'], 53);
})
.add('Immutable.setIn Array/List', function() {
list.setIn([51, 'index'], 5);
})
.add('Seamless-Immutable setIn Array/List', function () {
siList.setIn([52, 'index'], 53);
})
.add('Immutable.setIn Obj/Map', function() {
map.setIn(['data', 'foo'], 'new bar');
})
.add('Seamless-Immutable.setIn Obj/Map', function() {
siMap.setIn(['data', 'foo'], 'new bar');
})
// add listeners
.on('cycle', function(event) {
console.log('');
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment