Created
February 18, 2014 15:39
-
-
Save ikr7/9073311 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
//bench.js | |
var bench = function(a){ | |
a.benches.forEach(function(e){ | |
console.time(e.name); | |
for(var i = 0; i < a.count; i++){ | |
e.func(); | |
} | |
console.timeEnd(e.name); | |
}); | |
}; | |
//usage | |
bench({ | |
'count': 1000000, | |
'benches': [ | |
{ | |
'name': 'use with', | |
'func': function(){ | |
with(Math){ | |
var r = random(); | |
} | |
} | |
}, { | |
'name': 'no use with', | |
'func': function(){ | |
var r = Math.random(); | |
} | |
} | |
] | |
}); | |
/* | |
Output: | |
use with: 235ms | |
no use with: 6ms | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment