Last active
August 29, 2015 13:58
-
-
Save jmervine/9981218 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
/* 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