Skip to content

Commit

Permalink
filter and foldl benchmark suites
Browse files Browse the repository at this point in the history
  • Loading branch information
buzzdecafe committed Jul 4, 2014
1 parent 1046ef4 commit 6d407d4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ node_modules
coverage
*.swp


/node_modules
/examples/math.html
/examples/math.js
36 changes: 36 additions & 0 deletions bench/filter.bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var _ = require('lodash');
var filter = require('../ramda').filter;
var Benchmark = require('benchmark');
var fs = require('fs');
var out = './report/filter-' + (new Date()).toISOString() + '.json';
var suite = new Benchmark.Suite;

var nums = [8,2,85,2,34,3,23,247,57,8,0,6,5,46,54,643];
function isEven(x) { return x % 2 === 0; }
var filterEven = filter(isEven);

suite
.add('_.filter(nums, isEven)', function() {
_.filter(nums, isEven);
})
.add('filter(isEven, nums)', function() {
filter(isEven, nums);
})
.add('filter(isEven)(nums)', function() {
filter(isEven)(nums);
})
.add('filterEven(nums)', function() {
filterEven(nums);
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
fs.writeFile(out, JSON.stringify(this), function(err) {
if (err) { console.log('failed to write ' + out); }
else { console.log('saved ' + out); }
});
})
.run();

36 changes: 36 additions & 0 deletions bench/foldl.bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var _ = require('lodash');
var foldl = require('../ramda').foldl;
var Benchmark = require('benchmark');
var fs = require('fs');
var out = './report/foldl-' + (new Date()).toISOString() + '.json';
var suite = new Benchmark.Suite;

var nums = [8,2,85,2,34,3,23,247,57,8,0,6,5,46,54,643];
function add(acc, x) { return acc + x; }
var foldlAdd = foldl(add, 0);

suite
.add('_.reduce(nums, add, 0)', function() {
_.reduce(nums, add, 0);
})
.add('foldl(add, 0, nums)', function() {
foldl(add, 0, nums);
})
.add('foldl(add, 0)(nums)', function() {
foldl(add, 0)(nums);
})
.add('foldlAdd(nums)', function() {
foldlAdd(nums);
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
fs.writeFile(out, JSON.stringify(this), function(err) {
if (err) { console.log('failed to write ' + out); }
else { console.log('saved ' + out); }
});
})
.run();

0 comments on commit 6d407d4

Please sign in to comment.