Skip to content

Instantly share code, notes, and snippets.

@jmervine
Last active August 29, 2015 13:58
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 jmervine/9981218 to your computer and use it in GitHub Desktop.
Save jmervine/9981218 to your computer and use it in GitHub Desktop.
/* setup
*
* npm install underscore extend benchmark
*
*/
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var bento = require('./bento'); // 122K json file
var updated = {
SearchResult: {
BusinessListings: []
}
};
for (var i = 0; i < 10; i++) {
updated.SearchResult.BusinessListings[i] = { Zip: 12345 };
}
function ex(obj) {
Array.prototype.slice.call(arguments, 1).forEach(function (source) {
if (source) {
for (var prop in source) {
if (source.hasOwnProperty(prop)) {
obj[prop] = source[prop];
}
}
}
});
return obj;
}
var _ = require('underscore');
var extend = require('extend');
// add tests
suite.add('Custom Extend', function() {
var e = ex(bento, updated);
})
.add('Underscore Extend', function() {
var e = _.extend(bento, updated);
})
.add('Extend Module', function() {
var e = extend(bento, updated);
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})
// run async
.run({ 'async': true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment