Created
September 2, 2016 10:19
-
-
Save larshp/046285a8e1e13caee0b8ebaaadcfb012 to your computer and use it in GitHub Desktop.
This file contains 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 Timer { | |
private times; | |
private count; | |
private startTime: number; | |
public constructor() { | |
this.times = {}; | |
this.count = {}; | |
} | |
public start(): void { | |
this.startTime = new Date().getTime(); | |
} | |
public stop(name: string): void { | |
let end = new Date().getTime(); | |
let time = end - this.startTime; | |
if (this.times[name]) { | |
this.times[name] = this.times[name] + time; | |
this.count[name] = this.count[name] + 1; | |
} else { | |
this.times[name] = time; | |
this.count[name] = 1; | |
} | |
} | |
public output(filename: string) { | |
for (let name in this.times) { | |
if (this.times[name] > 100) { | |
console.log(name + "\t" + this.times[name] + "ms\t" + this.count[name] + "\t" + filename); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment