benchforge 0.1.3 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,12 +7,13 @@ import type {
7
7
  } from "../BenchMatrix.ts";
8
8
  import { runMatrix } from "../BenchMatrix.ts";
9
9
  import type { BenchGroup, BenchmarkSpec, BenchSuite } from "../Benchmark.ts";
10
- import type { BenchmarkReport, ReportGroup } from "../BenchmarkReport.ts";
10
+ import type {
11
+ BenchmarkReport,
12
+ ReportGroup,
13
+ ResultsMapper,
14
+ } from "../BenchmarkReport.ts";
11
15
  import { reportResults } from "../BenchmarkReport.ts";
12
- import {
13
- type BrowserProfileResult,
14
- profileBrowser,
15
- } from "../browser/BrowserHeapSampler.ts";
16
+ import type { BrowserProfileResult } from "../browser/BrowserHeapSampler.ts";
16
17
  import { exportBenchmarkJson } from "../export/JsonExport.ts";
17
18
  import { exportPerfettoTrace } from "../export/PerfettoExport.ts";
18
19
  import type { GitVersion } from "../GitUtils.ts";
@@ -362,12 +363,13 @@ function buildReportSections(
362
363
  hasOptData: boolean,
363
364
  ) {
364
365
  const sections = adaptive
365
- ? [adaptiveSection, runsSection, totalTimeSection]
366
- : [timeSection, runsSection];
366
+ ? [adaptiveSection, totalTimeSection]
367
+ : [timeSection];
367
368
 
368
369
  if (gcStats) sections.push(gcStatsSection);
369
370
  if (hasCpuData) sections.push(cpuSection);
370
371
  if (hasOptData) sections.push(optSection);
372
+ sections.push(runsSection);
371
373
 
372
374
  return sections;
373
375
  }
@@ -386,6 +388,20 @@ export async function benchExports(
386
388
  /** Run browser profiling via Playwright + CDP, report with standard pipeline */
387
389
  export async function browserBenchExports(args: DefaultCliArgs): Promise<void> {
388
390
  warnBrowserFlags(args);
391
+
392
+ let profileBrowser: typeof import("../browser/BrowserHeapSampler.ts").profileBrowser;
393
+ try {
394
+ ({ profileBrowser } = await import("../browser/BrowserHeapSampler.ts"));
395
+ } catch {
396
+ throw new Error(
397
+ "playwright is required for browser benchmarking (--url).\n\n" +
398
+ "Quick start: npx benchforge-browser --url <your-url>\n\n" +
399
+ "Or install manually:\n" +
400
+ " npm install playwright\n" +
401
+ " npx playwright install chromium",
402
+ );
403
+ }
404
+
389
405
  const url = args.url!;
390
406
  const { iterations, time } = args;
391
407
  const result = await profileBrowser({
@@ -396,7 +412,9 @@ export async function browserBenchExports(args: DefaultCliArgs): Promise<void> {
396
412
  stackDepth: args["heap-depth"],
397
413
  },
398
414
  headless: args.headless,
399
- chromeArgs: args["chrome-args"]?.split(/\s+/).filter(Boolean),
415
+ chromeArgs: args["chrome-args"]
416
+ ?.flatMap(a => a.split(/\s+/))
417
+ .filter(Boolean),
400
418
  timeout: args.timeout,
401
419
  gcStats: args["gc-stats"],
402
420
  maxTime: iterations ? Number.MAX_SAFE_INTEGER : time * 1000,
@@ -404,28 +422,37 @@ export async function browserBenchExports(args: DefaultCliArgs): Promise<void> {
404
422
  });
405
423
 
406
424
  const name = new URL(url).pathname.split("/").pop() || "browser";
407
- const hasSamples = result.samples && result.samples.length > 0;
408
425
  const results = browserResultGroups(name, result);
426
+ printBrowserReport(result, results, args);
427
+ await exportReports({ results, args });
428
+ }
409
429
 
410
- // Time report
430
+ /** Print browser benchmark tables and heap reports */
431
+ function printBrowserReport(
432
+ result: BrowserProfileResult,
433
+ results: ReportGroup[],
434
+ args: DefaultCliArgs,
435
+ ): void {
436
+ const hasSamples = result.samples && result.samples.length > 0;
437
+ const sections: ResultsMapper<any>[] = [];
411
438
  if (hasSamples || result.wallTimeMs != null) {
412
- console.log(reportResults(results, [timeSection, runsSection]));
439
+ sections.push(timeSection);
413
440
  }
414
-
415
- // GC stats table
416
441
  if (result.gcStats) {
417
- console.log(reportResults(results, [browserGcStatsSection]));
442
+ sections.push(browserGcStatsSection);
443
+ }
444
+ if (hasSamples || result.wallTimeMs != null) {
445
+ sections.push(runsSection);
446
+ }
447
+ if (sections.length > 0) {
448
+ console.log(reportResults(results, sections));
418
449
  }
419
-
420
- // Heap allocation report
421
450
  if (result.heapProfile) {
422
451
  printHeapReports(results, {
423
452
  ...cliHeapReportOptions(args),
424
453
  isUserCode: isBrowserUserCode,
425
454
  });
426
455
  }
427
-
428
- await exportReports({ results, args });
429
456
  }
430
457
 
431
458
  /** Wrap browser profile result as ReportGroup[] for the standard pipeline */