Created
February 5, 2011 04:17
-
-
Save mhayashi/812191 to your computer and use it in GitHub Desktop.
if vs. assert vs. should
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
var assert = require('assert'); | |
var should = require('should'); | |
var a = 1; | |
var times = 1000000; | |
console.time('if '); | |
while(times--) { | |
if (a === 1) ; | |
} | |
console.timeEnd('if '); | |
times = 1000000; | |
console.time('assert '); | |
while(times--) { | |
assert.equal(a, 1); | |
} | |
console.timeEnd('assert '); | |
times = 1000000; | |
console.time('should '); | |
while(times--){ | |
a.should.equal(1); | |
} | |
console.timeEnd('should '); |
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
$ node bench.js | |
if : 2ms | |
assert : 14ms | |
should : 3144ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment