Skip to content

Instantly share code, notes, and snippets.

@taion taion/omit-benchmark.js
Last active Jul 30, 2016

Embed
What would you like to do?
const Benchmark = require('benchmark');
const _ = require('lodash');
const props = {
className: 'foo',
onClick: () => null,
children: 'bar',
style: { top: 10 },
relay: {},
intl: {},
};
function customOmit(obj, keys) {
const retVal = {};
Object.keys(obj).forEach(key => {
if (keys.indexOf(key) === -1) {
retVal[key] = obj[key];
}
});
return retVal;
}
console.log('_.omit', _.omit(props, ['relay', 'intl']));
console.log('customOmit', customOmit(props, ['relay', 'intl']));
const suite = new Benchmark.Suite;
suite
.add('_.omit', () => (
_.omit(props, ['relay', 'intl'])
))
.add('customOmit', () => (
customOmit(props, ['relay', 'intl'])
))
.on('complete', () => {
suite.forEach(benchmark => {
console.log(benchmark.toString());
});
})
.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.