Last active
July 30, 2016 21:04
-
-
Save taion/fb85d0d91ab231db4aa4942e213e50da to your computer and use it in GitHub Desktop.
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
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