Last active
August 29, 2015 14:03
-
-
Save catdad/9721fcc01d5842008fac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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