microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/utils/node/stopWatch.ts
22lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. |
| 3 | |
| 4 | export class StopWatch { |
| 5 | private startTime = process.hrtime(); |
| 6 | private nanoSecondsInOneMilliSecond = 1000000; |
| 7 | private milliSecondsInOneSecond = 1000; |
| 8 | |
| 9 | public stopAsMilliseconds(): number { |
| 10 | let ellapsedTime = process.hrtime(this.startTime); |
| 11 | let smallPartInNanoSeconds = ellapsedTime[1]; |
| 12 | let smallPartInMilliSeconds = smallPartInNanoSeconds / this.nanoSecondsInOneMilliSecond; |
| 13 | let bigPartInSeconds = ellapsedTime[0]; |
| 14 | let bigPartInMilliSeconds = bigPartInSeconds * this.milliSecondsInOneSecond; |
| 15 | let ellapsedTimeInMilliSeconds = bigPartInMilliSeconds + smallPartInMilliSeconds; |
| 16 | return ellapsedTimeInMilliSeconds; |
| 17 | } |
| 18 | |
| 19 | public stopAsSeconds(): number { |
| 20 | return this.stopAsMilliseconds() / this.milliSecondsInOneSecond; |
| 21 | } |
| 22 | } |