Skip to content

Instantly share code, notes, and snippets.

@just-boris
Last active March 5, 2016 08:07
Show Gist options
  • Save just-boris/6375c63bd8f334170511 to your computer and use it in GitHub Desktop.
Save just-boris/6375c63bd8f334170511 to your computer and use it in GitHub Desktop.
Redux#1468
node_modules/
dist/

Benchmark for issue 1468

How to run

  1. Clone this
  2. npm install
  3. node index.js

If you want to check results in browser, run npm run build and open index.html in the browser

Results

Platform info:
Darwin 15.3.0 x64
Node.JS 5.6.0
V8 4.6.85.31
Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz × 4

ArraySize: 10000
spread x 416 ops/sec ±3.11% (77 runs sampled)
filter x 1,137 ops/sec ±2.83% (83 runs sampled)

ArraySize: 1000
spread x 4,894 ops/sec ±1.45% (87 runs sampled)
filter x 112,862 ops/sec ±4.29% (77 runs sampled)

ArraySize: 100
spread x 783,681 ops/sec ±1.46% (86 runs sampled)
filter x 1,212,082 ops/sec ±0.98% (89 runs sampled)

ArraySize: 50
spread x 779,554 ops/sec ±2.33% (83 runs sampled)
filter x 1,174,323 ops/sec ±1.18% (87 runs sampled)
Platform info:
Darwin 15.3.0 x64
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:44.0) Gecko/20100101 Firefox/44.0
Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz × 4

ArraySize: 10000
spread x 1,686 ops/sec ±3.45% (59 runs sampled)
filter x 5,189 ops/sec ±0.89% (31 runs sampled)

ArraySize: 1000
spread x 365,839 ops/sec ±2.14% (62 runs sampled
filter x 1,261,945 ops/sec ±5.96% (56 runs sampled)

ArraySize: 100
spread x 624,463 ops/sec ±2.34% (59 runs sampled)
filter x 1,307,458 ops/sec ±3.89% (58 runs sampled)

ArraySize: 50
spread x 651,318 ops/sec ±2.82% (61 runs sampled)
filter x 1,279,511 ops/sec ±4.45% (54 runs sampled)

Post your own result in comment if you would like to share

<html>
<head>
<script src="dist/bundle.js"></script>
</head>
<body>
See console for test results...
</body>
</html>
"use strict";
var Benchmark = require('benchmark/benchmark');
global.Redux = require('redux');
function printPlatform() {
console.log("\nPlatform info:");
var os = require("os");
var v8 = process.versions.v8;
var node = process.versions.node;
var plat = os.type() + " " + os.release() + " " + os.arch() + "\nNode.JS " + node + "\nV8 " + v8;
var cpus = os.cpus().map(function(cpu) {
return cpu.model;
}).reduce(function(o, model) {
if(!o[model]) o[model] = 0;
o[model]++;
return o;
}, {});
cpus = Object.keys(cpus).map(function(key) {
return key + " \u00d7 " + cpus[key];
}).join("\n");
console.log(plat + "\n" + cpus + "\n");
}
var ARRAY_SIZE = 50;
global.getInitialState = function() {
var items = [];
for(var i = 0; i < ARRAY_SIZE; i++) {
items.push(i);
}
return items;
}
function removeItem() {
var state = this.store.getState();
var index = Math.floor(state.length / 2);
this.store.dispatch({type: 'REMOVE', childId: state[index]});
}
var testSuite = new Benchmark.Suite()
.add('spread', {
setup: function() {
function reducer(state, action) {
if (typeof state === 'undefined') {
return [];
}
switch (action.type) {
case 'REMOVE':
const index = state.indexOf(action.childId)
return [
...state.slice(0, index),
...state.slice(index + 1)
]
default:
return state;
}
}
this.store = Redux.createStore(reducer, getInitialState());
},
fn: removeItem
})
.add('filter', {
setup: function() {
function reducer(state, action) {
if (typeof state === 'undefined') {
return [];
}
switch (action.type) {
case 'REMOVE':
return state.filter(id => id !== action.childId)
default:
return state;
}
}
this.store = Redux.createStore(reducer, getInitialState());
},
fn: removeItem
})
.on("cycle", function(e) {
console.log("" + e.target);
})
.on("error", function(e) {
console.log(e.target.error.stack);
});
printPlatform();
console.log('ArraySize:', ARRAY_SIZE)
testSuite.run();
{
"name": "redux-perf",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"benchmark": "^2.1.0",
"redux": "^3.3.1"
},
"devDependencies": {
"webpack": "^1.12.14"
},
"scripts": {
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC"
}
module.exports = {
entry: './index.js',
output: {
filename: 'bundle.js',
path: __dirname + '/dist'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment