-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae8179f
commit eff5539
Showing
43 changed files
with
928 additions
and
284 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { performance } from 'perf_hooks'; | ||
|
||
export class Stopwatch { | ||
private _start: number | undefined; | ||
private _finish: number | undefined; | ||
|
||
start() { | ||
if (this._start) { | ||
this._finish = undefined; | ||
} | ||
|
||
this._start = performance.now(); | ||
} | ||
|
||
finish() { | ||
if (!this._start) { | ||
throw new Error('Cannot finish a stopwatch that have not started'); | ||
} | ||
this._finish = performance.now(); | ||
} | ||
|
||
elapsedTime(): number | undefined { | ||
if (!this._start || !this._finish) { | ||
return undefined; | ||
} | ||
|
||
return this._start - this._finish; | ||
} | ||
|
||
reset() { | ||
this._start = this._finish = undefined; | ||
} | ||
} |
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
Oops, something went wrong.