Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vanilla funcs #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/assoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
}
3 changes: 2 additions & 1 deletion src/assocPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will mutate the value used by all the other tests. Would need a loop here through the path I think and return a new object.

}
3 changes: 3 additions & 0 deletions src/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ module.exports = ({ list }) => {
})
.add('lodash', function () {
_.find(pred, value);
})
.add('vanilla', function() {
value.find(pred);
});
};
6 changes: 6 additions & 0 deletions src/mapFilterReduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ module.exports = ({ list }) => {
R.filter(even),
R.map(inc)
)(value);
})
.add('vanilla', () => {
value
.map(inc)
.filter(even)
.reduce(add, 0)
});
}
14 changes: 12 additions & 2 deletions src/mapIncAndReverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
});
})

}
5 changes: 3 additions & 2 deletions src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]; });
}