forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1046ef4
commit 6d407d4
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ node_modules | |
coverage | ||
*.swp | ||
|
||
|
||
/node_modules | ||
/examples/math.html | ||
/examples/math.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
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(); | ||
|
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
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(); | ||
|