Skip to content

Instantly share code, notes, and snippets.

@anasnakawa
Created October 15, 2014 12:53
Show Gist options
  • Save anasnakawa/822a6fba65eaf2577866 to your computer and use it in GitHub Desktop.
Save anasnakawa/822a6fba65eaf2577866 to your computer and use it in GitHub Desktop.
/**
* 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