Benchmarking d3-array.extent against a simple Array.reduce
const Benchmark = require('benchmark');
const suite = new Benchmark.Suite();
const ranger = require('power-ranger');
const data = ranger(1000, () => Math.random());
const d3extent = require('d3-array').extent;
const reduceExtent = data => {
return data.reduce(
(e, d) => [Math.min(e[0], +d), Math.max(e[1], +d)],
[Infinity, -Infinity]
);
};
suite.add('d3array.extent', function() {
d3extent(data);
})
.add('reduce', function() {
reduceExtent(data);
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });
no comments