Skip to content

Instantly share code, notes, and snippets.

@catdad
Last active August 29, 2015 14:03
Show Gist options
  • Save catdad/9721fcc01d5842008fac to your computer and use it in GitHub Desktop.
Save catdad/9721fcc01d5842008fac to your computer and use it in GitHub Desktop.
var c = {
hash: {},
useNative: true,
time: function(str){
if (this.useNative && console && console.time) console.time(str);
else this.hash[str] = (new Date()).getTime();
},
timeEnd: function(str){
if (this.useNative && console && console.time && console.timeEnd) console.timeEnd(str);
else if (this.hash[str]){
this.log( str + ': ' + ((new Date()).getTime() - this.hash[str]) + 'ms' );
this.hash[str] = undefined;
}
},
log: function(str){
console && console.log && console.log.apply(console, arguments);
}
};
// usage:
c.time('my test case');
// do work here
c.timeEnd('my test case');
//prints:
//> my test case: XXXms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment