Skip to content

Instantly share code, notes, and snippets.

@Dammmien
Last active September 30, 2016 13:24
Show Gist options
  • Save Dammmien/b017b00ddb0d1b1fe186 to your computer and use it in GitHub Desktop.
Save Dammmien/b017b00ddb0d1b1fe186 to your computer and use it in GitHub Desktop.
TimeTracker
class TimeTracker {
constructor() {
this.timers = {};
}
logLoadTimes() {
var loadTimes = chrome.loadTimes();
console.log( `commitLoadTime .............. ${( loadTimes.commitLoadTime - loadTimes.startLoadTime ).toFixed( 2 )}s` );
console.log( `finishDocumentLoadTime ...... ${( loadTimes.finishDocumentLoadTime - loadTimes.startLoadTime ).toFixed( 2 )}s` );
console.log( `finishLoadTime .............. ${( loadTimes.finishLoadTime - loadTimes.startLoadTime ).toFixed( 2 )}s` );
}
startTimer( name ) {
this.timers[ name ] = Date.now();
}
endTimer( name ) {
let time = Date.now() - this.timers[ name ];
console.log( `${name} ...... ${ time > 1000 ? time / 1000 : time} ${ time > 1000 ? "s" : "ms"}` );
}
}
let tracker = new TimeTracker();
tracker.startTimer( "Foo Timer" );
setTimeout( () => tracker.endTimer( "Foo Timer" ), 500 );
// Foo Timer ...... 501 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment