Created
June 13, 2016 15:28
-
-
Save yuanqing/e2e382e3d38bfd4e2be28d834b8cad11 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
$ node index.js | |
ternary, true x 84,415,848 ops/sec ±2.47% (78 runs sampled) | |
ternary, false x 73,646,719 ops/sec ±5.86% (73 runs sampled) | |
&& and ||, true x 78,748,665 ops/sec ±2.80% (72 runs sampled) | |
&& and ||, false x 80,837,863 ops/sec ±1.84% (81 runs sampled) | |
Fastest is ternary, true |
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
var Benchmark = require('benchmark'); | |
var suite = new Benchmark.Suite; | |
var foo = true; | |
var bar = false; | |
suite.add('ternary, true', function() { | |
foo ? 1 : 2; | |
}).add('ternary, false', function() { | |
bar ? 1 : 2; | |
}).add('&& and ||, true', function() { | |
foo && 1 || 2; | |
}).add('&& and ||, false', function() { | |
bar && 1 || 2; | |
}).on('cycle', function(event) { | |
console.log(String(event.target)); | |
}).on('complete', function() { | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}).run({ async: true }); |
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
{ | |
"dependencies": { | |
"benchmark": "^2.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment