Created
April 15, 2013 17:15
-
-
Save azulus/5389688 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Tested in Node.js v0.10.3 | |
// * RESULTS * | |
// custom bind x 29,388,127 ops/sec ±1.46% (95 runs sampled) | |
// native bind x 636,295 ops/sec ±2.66% (81 runs sampled) | |
// custom bind invoke x 45,884,456 ops/sec ±1.19% (95 runs sampled) | |
// native bind invoke x 5,424,592 ops/sec ±1.76% (96 runs sampled) | |
// * TESTS * | |
var Benchmark = require('benchmark'); | |
var suite = new Benchmark.Suite; | |
var someArg = 1; | |
function testFunc(arg) {} | |
function wrap(f, context, var_args) { | |
var args = Array.prototype.slice.call(arguments, 2) | |
return function() { | |
return f.apply(context, args); | |
} | |
} | |
var nativeBound = testFunc.bind(null); | |
var customBound = wrap(testFunc); | |
// binding tests | |
suite.add('custom bind', function() { | |
wrap(testFunc, null, someArg); | |
}) | |
.add('native bind', function() { | |
testFunc.bind(null, someArg); | |
}) | |
// bind invocation tests | |
.add('custom bind invoke', function() { | |
customBound(); | |
}) | |
.add('native bind invoke', function() { | |
nativeBound(); | |
}) | |
// add listeners | |
.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}) | |
.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment