Skip to content

Commit

Permalink
improve playground runner
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitropoulos committed Sep 1, 2024
1 parent 1c9f4c8 commit 1721f5a
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 67 deletions.
6 changes: 3 additions & 3 deletions packages/playground/david-blass-incredibleness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type sl=s['length']// =>

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

type al=a['activeLocals'] // =>
type af=a['activeFuncId'] // =>
type ab=a['activeBranches']// =>
type al=e['activeLocals'] // =>
type af=e['activeFuncId'] // =>
type ab=e['activeBranches']// =>

type ec=e['executionContexts']
type c0f=ec[0]['funcId'] // =>
Expand Down
23 changes: 19 additions & 4 deletions packages/playground/evaluate/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,26 @@ export const readStringFromMemory = true;
*/
export const comeUpForAirEvery = 500;

export const initialConditions = {
current: 0,
stopAt: 1_000_000,
export interface InitialConditions {
/**
* the current instruction to start from.
* if greater than 0 it will automatically not clear prior results
*/
startAt: 0 | number;

/** if `Infinity`, the fun never stops. otherwise it will forcibly halt at a the specified instructions count */
stopAt: number;

/** the number of digits in the filenames and types. so a value of 4 will yield "0001", "0002", etc. */
digits: number;
}

export const initialConditions = {
startAt: 0,
stopAt: Infinity, // 1_000_000,
digits: 8,
} satisfies InitialConditions;

export const simpleTypeMode = process.argv.includes('--simple');

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

export const formatCurrent = (current: number) => String(current).padStart(6, '0');
export const formatCurrent = (current: number) => String(current).padStart(initialConditions.digits, '0');
export const createResultFilePath = (current: number) => join(resultsDirectory, `results-${formatCurrent(current)}.ts`)
export const statsJsonPath = (current: number) => join(statsDirectory, `stats-${formatCurrent(current)}.json`);
export const shouldTakeABreath = (timeSpentUnderwater: number, current: number) => current === 0 || timeSpentUnderwater >= comeUpForAirEvery;
80 changes: 80 additions & 0 deletions packages/playground/evaluate/metering.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// this is a micro metering library

const metrics = [
'getProgram',
'getSourceFile',
'getTypeAlias',
'checker',
'getTypeAtLocation',
'typeToString',
'formatter',
'writeResults',
'total'
] as const;

export type Metric = typeof metrics[number];

export type Metering = Record<
Metric,
number | null
>;

export type MeteringDefinite = Record<
Metric,
number
>;

const metering = metrics.reduce((acc, metric) => ({
...acc,
[metric]: null,
}), {} as Metering);

export const resetMeter = () => {
for (const metric in metering) {
metering[metric as Metric] = null;
}
}

export const meter = (metric: Metric) => ({
start: () => {
if (metering[metric] !== null) {
throw new Error(`bro. come on. metering ${metric} was already started!`);
}
metering[metric] = performance.now();
},
stop: () => {
const start = metering[metric];
if (start === null) {
throw new Error(`metering ${metric} was not started. get your shit together.`);
}
const result = performance.now() - start;
metering[metric] = result;
totals[metric] += result;
},
})

export const finalizeMeter = () => {
for (const metric in metering) {
if (metering[metric as keyof Metering] === null) {
throw new Error(`hey dumb dumb. you forgot to stop measurement for ${metric}`)
}
}
return metering as MeteringDefinite
}

const totals = metrics.reduce((acc, metric) => ({
...acc,
[metric]: 0,
}), {} as MeteringDefinite);

export const printTotals = () => {
console.log(
Object.fromEntries(
Object.entries(totals).map(([metric, value]) => ([
metric,
// truncate all the values in totals to 3 decimal points
Number(value.toFixed(3))
]))
)
);
}
Loading

0 comments on commit 1721f5a

Please sign in to comment.