-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.ts
29 lines (22 loc) · 882 Bytes
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { CharRange } from "../src/char-set";
export function printRanges(ranges: Iterable<CharRange>): string {
return `JSON.parse('${JSON.stringify([...ranges])}')`;
}
export function logDurations(durations: number[], label?: string): void {
durations.sort((a, b) => a - b);
const avg = durations.reduce((a, b) => a + b, 0) / durations.length;
const max = Math.max(...durations);
const median =
durations.length % 2 === 0
? (durations[durations.length / 2 - 1] + durations[durations.length / 2]) / 2
: durations[(durations.length - 1) / 2];
const parts: string[] = [];
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (label) {
parts.push(label);
}
parts.push(`avg=${+avg.toExponential(2)}ms`);
parts.push(`med=${+median.toExponential(2)}ms`);
parts.push(`max=${+max.toExponential(2)}ms`);
console.log(parts.join("\t"));
}