Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/util/vs/base/common/stopwatch.ts
13405 views
1
//!!! DO NOT modify, this file was COPIED from 'microsoft/vscode'
2
3
/*---------------------------------------------------------------------------------------------
4
* Copyright (c) Microsoft Corporation. All rights reserved.
5
* Licensed under the MIT License. See License.txt in the project root for license information.
6
*--------------------------------------------------------------------------------------------*/
7
8
declare const globalThis: { performance: { now(): number } };
9
const performanceNow = globalThis.performance.now.bind(globalThis.performance);
10
11
export class StopWatch {
12
13
private _startTime: number;
14
private _stopTime: number;
15
16
private readonly _now: () => number;
17
18
public static create(highResolution?: boolean): StopWatch {
19
return new StopWatch(highResolution);
20
}
21
22
constructor(highResolution?: boolean) {
23
this._now = highResolution === false ? Date.now : performanceNow;
24
this._startTime = this._now();
25
this._stopTime = -1;
26
}
27
28
public stop(): void {
29
this._stopTime = this._now();
30
}
31
32
public reset(): void {
33
this._startTime = this._now();
34
this._stopTime = -1;
35
}
36
37
public elapsed(): number {
38
if (this._stopTime !== -1) {
39
return this._stopTime - this._startTime;
40
}
41
return this._now() - this._startTime;
42
}
43
}
44
45