Path: blob/main/extensions/copilot/src/util/vs/base/common/stopwatch.ts
13405 views
//!!! DO NOT modify, this file was COPIED from 'microsoft/vscode'12/*---------------------------------------------------------------------------------------------3* Copyright (c) Microsoft Corporation. All rights reserved.4* Licensed under the MIT License. See License.txt in the project root for license information.5*--------------------------------------------------------------------------------------------*/67declare const globalThis: { performance: { now(): number } };8const performanceNow = globalThis.performance.now.bind(globalThis.performance);910export class StopWatch {1112private _startTime: number;13private _stopTime: number;1415private readonly _now: () => number;1617public static create(highResolution?: boolean): StopWatch {18return new StopWatch(highResolution);19}2021constructor(highResolution?: boolean) {22this._now = highResolution === false ? Date.now : performanceNow;23this._startTime = this._now();24this._stopTime = -1;25}2627public stop(): void {28this._stopTime = this._now();29}3031public reset(): void {32this._startTime = this._now();33this._stopTime = -1;34}3536public elapsed(): number {37if (this._stopTime !== -1) {38return this._stopTime - this._startTime;39}40return this._now() - this._startTime;41}42}434445