Skip to content

Instantly share code, notes, and snippets.

@taion
Last active July 30, 2016 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taion/fb85d0d91ab231db4aa4942e213e50da to your computer and use it in GitHub Desktop.
Save taion/fb85d0d91ab231db4aa4942e213e50da to your computer and use it in GitHub Desktop.
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