Created
October 15, 2014 12:53
-
-
Save anasnakawa/822a6fba65eaf2577866 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
/** | |
* polyfilling console.time & timeEnd | |
* on IE | |
*/ | |
(function( console ) { | |
// cache to hold running timers | |
console._timers = {}; | |
/** | |
* start timer | |
* | |
* @param {string} key timer name | |
*/ | |
console.time = function( key ) { | |
console._timers[ key ] = new Date().getTime(); | |
} | |
/** | |
* end timer | |
* | |
* @param {string} key | |
*/ | |
console.timeEnd = function( key ) { | |
var current = new Date().getTime(); | |
var started = console._timers[ key ]; | |
console.info( '{key}: {duration}ms'.replace( /{key}/, key ).replace( /{duration}/, current - started ) ); | |
// release timer | |
delete console._timers[ key ]; | |
} | |
})( this.console = this.console || {} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment