Last active
April 16, 2017 07:49
-
-
Save jlongster/d655170bcdc658d3eb0e to your computer and use it in GitHub Desktop.
transducers w/immutable-js
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
# benchmark immutable.js with my transducers lib: https://github.com/jlongster/transducers.js | |
% node bench/immut.js | |
Immutable map/filter (1000) x 5,497 ops/sec ±2.63% (91 runs sampled) | |
transducer map/filter (1000) x 7,309 ops/sec ±0.73% (100 runs sampled) | |
Immutable map/filter (100000) x 62.73 ops/sec ±0.85% (67 runs sampled) | |
transducer map/filter (100000) x 80.15 ops/sec ±0.48% (71 runs sampled) |
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
// benchmark immutable.js with my transducers lib: https://github.com/jlongster/transducers.js | |
var Benchmark = require('benchmark'); | |
var t = require('../transducers'); | |
var Immutable = require('immutable'); | |
var suite = Benchmark.Suite('transducers'); | |
function benchArray(n) { | |
var arr = new Immutable.Range(0, n).toVector(); | |
suite | |
.add('Immutable map/filter (' + n + ')', function() { | |
arr.map(function(x) { return x + 10; }) | |
.map(function(x) { return x * 2; }) | |
.filter(function(x) { return x % 5 === 0; }) | |
.filter(function(x) { return x % 2 === 0; }) | |
.toVector(); | |
}) | |
.add('transducer map/filter (' + n + ')', function() { | |
Immutable.Vector.from( | |
t.seq(arr, | |
t.compose( | |
t.map(function(x) { return x + 10; }), | |
t.map(function(x) { return x * 2; }), | |
t.filter(function(x) { return x % 5 === 0; }), | |
t.filter(function(x) { return x % 2 === 0; }))) | |
) | |
}); | |
} | |
benchArray(1000); | |
benchArray(100000); | |
suite.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}); | |
suite.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment