Skip to content

Instantly share code, notes, and snippets.

@ikr7
Created February 18, 2014 15:39
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 ikr7/9073311 to your computer and use it in GitHub Desktop.
Save ikr7/9073311 to your computer and use it in GitHub Desktop.
適当にベンチするやつ
//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