From ff08c09cdb5d5e925cc1a0021e1e087862602f35 Mon Sep 17 00:00:00 2001 From: David Daniel Date: Wed, 15 Mar 2017 01:17:21 -0700 Subject: [PATCH 1/2] add vanilla funcs --- src/assoc.js | 4 +++- src/assocPath.js | 3 ++- src/find.js | 3 +++ src/mapFilterReduce.js | 6 ++++++ src/mapIncAndReverse.js | 14 ++++++++++++-- src/path.js | 5 +++-- 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/assoc.js b/src/assoc.js index 86d1327..85c25c7 100644 --- a/src/assoc.js +++ b/src/assoc.js @@ -19,5 +19,7 @@ module.exports = ({ object }) => { .add('lodash/fp (String)' , () => { fp.set(prop, 42, value); }) .add('lodash/fp (Array)' , () => { fp.set([prop], 42, value); }) // .add('mori.assoc' , () => { mori.assoc(moriVal, path, 42); }) - .add('ramda' , () => { R.assoc(prop, 42, value); }); + .add('ramda' , () => { R.assoc(prop, 42, value); }) + .add('vanilla' , () => { Object.assign({}, value, { [prop]: 42 }); + }); } diff --git a/src/assocPath.js b/src/assocPath.js index ccf545a..f003440 100644 --- a/src/assocPath.js +++ b/src/assocPath.js @@ -11,5 +11,6 @@ module.exports = ({ object }) => { return suite .add('immutable', () => { immVal.setIn(path, 42); }) .add('ramda', () => { R.assocPath(path, 42, value); }) - .add('lodash', () => { _.update(pathStr, 42, value); }); + .add('lodash', () => { _.update(pathStr, 42, value); }) + .add('vanilla', () => { value[pathStr]=42 }); } diff --git a/src/find.js b/src/find.js index 8708172..4bda436 100644 --- a/src/find.js +++ b/src/find.js @@ -18,5 +18,8 @@ module.exports = ({ list }) => { }) .add('lodash', function () { _.find(pred, value); + }) + .add('vanilla', function() { + value.find(pred); }); }; diff --git a/src/mapFilterReduce.js b/src/mapFilterReduce.js index 934c8c8..d61dc86 100644 --- a/src/mapFilterReduce.js +++ b/src/mapFilterReduce.js @@ -64,5 +64,11 @@ module.exports = ({ list }) => { R.filter(even), R.map(inc) )(value); + }) + .add('vanilla', () => { + value + .map(inc) + .filter(even) + .reduce(add, 0) }); } diff --git a/src/mapIncAndReverse.js b/src/mapIncAndReverse.js index b4d3c8b..14983ad 100644 --- a/src/mapIncAndReverse.js +++ b/src/mapIncAndReverse.js @@ -9,6 +9,7 @@ const suite = new Benchmark.Suite('mapIncAndReverse'); module.exports = ({ object }) => { const { value } = object; const immVal = I.fromJS(value); + return suite .add('lodash.chain().map(inc).reverse()', () => { _.chain(value) @@ -23,15 +24,24 @@ module.exports = ({ object }) => { )(value); }) .add('lodash/fp.compose(reverse, map(inc))', () => { - fp.compose( + const ans = fp.compose( fp.reverse, fp.map(fp.inc) )(value); }) + .add('vanilla', () => { + const inc = k => value[k]+=1; + Object + .keys(value) // no object.values yet - stage-4 till May? + .map(inc) + .reverse(); + }) .add('ramda.compose(reverse, map(inc))', () => { + // is this intentional? this yields nothing since value is an object and reverse only takes a list R.compose( R.reverse, R.map(R.inc) )(value); - }); + }) + } diff --git a/src/path.js b/src/path.js index 11e85bf..a12504d 100644 --- a/src/path.js +++ b/src/path.js @@ -7,10 +7,11 @@ const suite = new Benchmark.Suite; module.exports = ({ object }) => { const { value, path, pathStr } = object; + console.log('path, pathStr', path, pathStr) const immVal = I.fromJS(value); return suite .add('immutable', () => { immVal.getIn(path); }) .add('ramda' , () => { R.path(path, value); }) - .add('lodash' , () => { _.get(pathStr, value); }); - + .add('lodash' , () => { _.get(pathStr, value); }) + .add('vanilla' , () => { value[pathStr]; }); } From 3634281c9ff82eb3fed7ff4ea0b452c313dc3ec9 Mon Sep 17 00:00:00 2001 From: David Daniel Date: Thu, 16 Mar 2017 02:52:50 -0700 Subject: [PATCH 2/2] fixes --- src/assocPath.js | 2 +- src/mapIncAndReverse.js | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/assocPath.js b/src/assocPath.js index f003440..456e45f 100644 --- a/src/assocPath.js +++ b/src/assocPath.js @@ -12,5 +12,5 @@ module.exports = ({ object }) => { .add('immutable', () => { immVal.setIn(path, 42); }) .add('ramda', () => { R.assocPath(path, 42, value); }) .add('lodash', () => { _.update(pathStr, 42, value); }) - .add('vanilla', () => { value[pathStr]=42 }); + .add('vanilla', () => { Object.assign({}, value, {[pathStr]:42})}); } diff --git a/src/mapIncAndReverse.js b/src/mapIncAndReverse.js index 14983ad..fd87916 100644 --- a/src/mapIncAndReverse.js +++ b/src/mapIncAndReverse.js @@ -30,17 +30,18 @@ module.exports = ({ object }) => { )(value); }) .add('vanilla', () => { - const inc = k => value[k]+=1; + const obj = Object.assign({}, value); + const inc = k => obj[k]+=1; Object - .keys(value) // no object.values yet - stage-4 till May? + .keys(obj) // no object.values yet - stage-4 till May? .map(inc) .reverse(); }) .add('ramda.compose(reverse, map(inc))', () => { - // is this intentional? this yields nothing since value is an object and reverse only takes a list R.compose( R.reverse, - R.map(R.inc) + R.map(R.inc), + R.values // almost twice as fast to convert to an array first )(value); })