Skip to content

Commit 0a973be

Browse files
committed
improve playground runner
1 parent 1c9f4c8 commit 0a973be

File tree

6 files changed

+183
-70
lines changed

6 files changed

+183
-70
lines changed

packages/playground/david-blass-incredibleness.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ type sl=s['length']// =>
1212

1313
type c=e['count']// =>
1414

15-
type al=a['activeLocals'] // =>
16-
type af=a['activeFuncId'] // =>
17-
type ab=a['activeBranches']// =>
15+
type al=e['activeLocals'] // =>
16+
type af=e['activeFuncId'] // =>
17+
type ab=e['activeBranches']// =>
1818

1919
type ec=e['executionContexts']
2020
type c0f=ec[0]['funcId'] // =>

packages/playground/evaluate/config.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,26 @@ export const readStringFromMemory = true;
1313
*/
1414
export const comeUpForAirEvery = 500;
1515

16-
export const initialConditions = {
17-
current: 0,
18-
stopAt: 1_000_000,
16+
export interface InitialConditions {
17+
/**
18+
* the current instruction to start from.
19+
* if greater than 0 it will automatically not clear prior results
20+
*/
21+
startAt: 0 | number;
22+
23+
/** if `Infinity`, the fun never stops. otherwise it will forcibly halt at a the specified instructions count */
24+
stopAt: number;
25+
26+
/** the number of digits in the filenames and types. so a value of 4 will yield "0001", "0002", etc. */
27+
digits: number;
1928
}
2029

30+
export const initialConditions = {
31+
startAt: 0,
32+
stopAt: Infinity, // 1_000_000,
33+
digits: 8,
34+
} satisfies InitialConditions;
35+
2136
export const simpleTypeMode = process.argv.includes('--simple');
2237

2338
const __filename = fileURLToPath(import.meta.url);
@@ -33,7 +48,7 @@ export const bootstrapFilePath = join(resultsDirectory, 'bootstrap.ts');
3348
export const statsDirectory = join(resultsDirectory, 'stats');
3449
export const statsPath = join(statsDirectory, 'program-stats.json');
3550

36-
export const formatCurrent = (current: number) => String(current).padStart(6, '0');
51+
export const formatCurrent = (current: number) => String(current).padStart(initialConditions.digits, '0');
3752
export const createResultFilePath = (current: number) => join(resultsDirectory, `results-${formatCurrent(current)}.ts`)
3853
export const statsJsonPath = (current: number) => join(statsDirectory, `stats-${formatCurrent(current)}.json`);
3954
export const shouldTakeABreath = (timeSpentUnderwater: number, current: number) => current === 0 || timeSpentUnderwater >= comeUpForAirEvery;
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// this is a micro metering library
2+
3+
const metrics = [
4+
'getProgram',
5+
'getSourceFile',
6+
'getTypeAlias',
7+
'checker',
8+
'getTypeAtLocation',
9+
'typeToString',
10+
'formatter',
11+
'writeResults',
12+
'total'
13+
] as const;
14+
15+
export type Metric = typeof metrics[number];
16+
17+
export type Metering = Record<
18+
Metric,
19+
number | null
20+
>;
21+
22+
export type MeteringDefinite = Record<
23+
Metric,
24+
number
25+
>;
26+
27+
const metering = metrics.reduce((acc, metric) => ({
28+
...acc,
29+
[metric]: null,
30+
}), {} as Metering);
31+
32+
export const resetMeter = () => {
33+
for (const metric in metering) {
34+
metering[metric as Metric] = null;
35+
}
36+
}
37+
38+
export const meter = (metric: Metric) => ({
39+
start: () => {
40+
if (metering[metric] !== null) {
41+
throw new Error(`bro. come on. metering ${metric} was already started!`);
42+
}
43+
metering[metric] = performance.now();
44+
},
45+
stop: () => {
46+
const start = metering[metric];
47+
if (start === null) {
48+
throw new Error(`metering ${metric} was not started. get your shit together.`);
49+
}
50+
const result = performance.now() - start;
51+
metering[metric] = result;
52+
totals[metric] += result;
53+
},
54+
})
55+
56+
export const finalizeMeter = () => {
57+
for (const metric in metering) {
58+
if (metering[metric as keyof Metering] === null) {
59+
throw new Error(`hey dumb dumb. you forgot to stop measurement for ${metric}`)
60+
}
61+
}
62+
return metering as MeteringDefinite
63+
}
64+
65+
const totals = metrics.reduce((acc, metric) => ({
66+
...acc,
67+
[metric]: 0,
68+
}), {} as MeteringDefinite);
69+
70+
export const printTotals = () => {
71+
console.log(
72+
Object.fromEntries(
73+
Object.entries(totals).map(([metric, value]) => ([
74+
metric,
75+
// truncate all the values in totals to 3 decimal points
76+
Number(value.toFixed(3))
77+
]))
78+
)
79+
);
80+
}

0 commit comments

Comments
 (0)