Skip to content

Commit 29668da

Browse files
committed
feat: extract timing helpers, capture raw float ms in mount benchmark
1 parent 791d528 commit 29668da

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

tests/benchmarks/mounting/collection-mount.bench.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { type ElectronApplication, type Page } from '@playwright/test';
33
import { openCollection, closeAllCollections } from '../../utils/page';
44
import { summarize } from '../utils/stats';
55
import { writeResults, buildResultEntry, type ResultEntry } from '../utils/results';
6+
import { startTimer } from '../utils/timing';
67
import { generateCollection, type CollectionFormat } from '../utils/collection-generator';
78
import * as path from 'path';
89
import * as fs from 'fs';
@@ -35,7 +36,7 @@ async function measureCollectionMount(
3536
});
3637
});
3738

38-
const start = performance.now();
39+
const timer = startTimer();
3940

4041
await page.getByTestId('collections-header-add-menu').click();
4142
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Open collection' }).click();
@@ -44,7 +45,7 @@ async function measureCollectionMount(
4445
await openCollection(page, collectionName);
4546
await page.evaluate(() => (window as any).__benchMountDone);
4647

47-
const elapsed = performance.now() - start;
48+
const elapsed = timer.elapsed();
4849

4950
await electronApp.evaluate(({ dialog }) => {
5051
if ((dialog as any).__originalShowOpenDialog) {
@@ -77,7 +78,7 @@ test.describe('Benchmark: Collection Mount', () => {
7778

7879
for (let i = 0; i < ITERATIONS_PER_SIZE; i++) {
7980
const elapsed = await measureCollectionMount(page, electronApp, collectionDir, collectionName);
80-
timings.push(Math.round(elapsed));
81+
timings.push(elapsed);
8182
}
8283

8384
const key = resultKey(format, size);

tests/benchmarks/utils/timing.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Timing utilities for benchmarks.
3+
*
4+
* Capture: const t = startTimer(); ...do work...; const ms = t.elapsed();
5+
* Convert: convertDuration(1500, 'ms', 's') === 1.5
6+
*/
7+
8+
export type DurationUnit = 'ns' | 'us' | 'ms' | 's';
9+
10+
const DURATION_TO_MS: Record<DurationUnit, number> = {
11+
ns: 1e-6,
12+
us: 1e-3,
13+
ms: 1,
14+
s: 1000
15+
};
16+
17+
export function startTimer() {
18+
const start = performance.now();
19+
return { elapsed: () => performance.now() - start };
20+
}
21+
22+
export function convertDuration(value: number, from: DurationUnit, to: DurationUnit): number {
23+
if (from === to) return value;
24+
return (value * DURATION_TO_MS[from]) / DURATION_TO_MS[to];
25+
}

0 commit comments

Comments
 (0)