Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/util.ts
13383 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import * as fs from 'fs';
6
import { join } from 'path';
7
import { SimulationOptions } from './base/simulationOptions';
8
9
export const REPO_ROOT = join(__dirname, '..'); // This must hold for both the esbuild bundle location and the source!
10
11
export function createScoreRenderer(opts: SimulationOptions, canUseBaseline: boolean): (score: number) => string {
12
// We can show pass count only when using the same number of runs as the baseline
13
const maxDigitCount = String(opts.nRuns).length;
14
return (
15
canUseBaseline
16
? (score: number) => `${String(score * opts.nRuns).padStart(maxDigitCount, ' ')}`
17
: (score: number) => `${String(score.toFixed(1)).padStart(3, ' ')}`
18
);
19
}
20
21
export function printTime(ms: number): string {
22
if (ms < 1000) {
23
return `${ms}ms`;
24
}
25
let seconds = (ms / 1000);
26
if (seconds < 60) {
27
return `${seconds.toFixed(1)}s`;
28
}
29
const minutes = Math.floor(seconds / 60);
30
seconds -= minutes * 60;
31
return `${minutes}m${Math.ceil(seconds)}s`;
32
}
33
34
export async function fileExists(filePath: string): Promise<boolean> {
35
try {
36
await fs.promises.access(filePath);
37
return true;
38
} catch (_) {
39
return false;
40
}
41
}
42
43