Last active
September 30, 2016 13:24
-
-
Save Dammmien/b017b00ddb0d1b1fe186 to your computer and use it in GitHub Desktop.
TimeTracker
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
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