Skip to content

Instantly share code, notes, and snippets.

@fearphage
Created November 8, 2009 19:46
Show Gist options
  • Save fearphage/229452 to your computer and use it in GitHub Desktop.
Save fearphage/229452 to your computer and use it in GitHub Desktop.
Very basic benchmarking function
function Benchmarker(count, args, that) {
if (Object.prototype.toString.call(args) != '[object Array]') args = [args];
function toArray() {
var name, results = this.results, array = [];
for (name in results) {
array.push(name + ': ' + results[name]);
}
return array;
}
function toString() {
var array = this.toArray();
return array.length ? array.join('ms\n') + 'ms' : 'Please run some tests firsts';
}
function test(name, fn) {
var i = count, ignore, start = new Date;
while (i--) ignore = fn.apply(that, args);
this.results[name] = (new Date) - start;
}
return {
results: {}
,toString: toString
,toArray: toArray
,test: test
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment