Skip to content

Instantly share code, notes, and snippets.

@mhayashi
Created February 5, 2011 04:17
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 mhayashi/812191 to your computer and use it in GitHub Desktop.
Save mhayashi/812191 to your computer and use it in GitHub Desktop.
if vs. assert vs. should
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 ');
$ 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