microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
a31b007c2af965bbb579b8e9ae0054a403891c95

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/utils/node/stopWatch.ts

22lines · modepreview

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

export class StopWatch {
    private startTime = process.hrtime();
    private nanoSecondsInOneMilliSecond = 1000000;
    private milliSecondsInOneSecond = 1000;

    public stopAsMilliseconds(): number {
        let ellapsedTime = process.hrtime(this.startTime);
        let smallPartInNanoSeconds = ellapsedTime[1];
        let smallPartInMilliSeconds = smallPartInNanoSeconds / this.nanoSecondsInOneMilliSecond;
        let bigPartInSeconds = ellapsedTime[0];
        let bigPartInMilliSeconds = bigPartInSeconds * this.milliSecondsInOneSecond;
        let ellapsedTimeInMilliSeconds = bigPartInMilliSeconds + smallPartInMilliSeconds;
        return ellapsedTimeInMilliSeconds;
    }

    public stopAsSeconds(): number {
        return this.stopAsMilliseconds() / this.milliSecondsInOneSecond;
    }
}