Skip to content

Commit f2ff26d

Browse files
committed
add size benchmark
1 parent c1a8714 commit f2ff26d

10 files changed

+121
-13
lines changed

webdriver-ts/src/benchmarkRunner.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@ import {
1717
cpuBenchmarkInfosArray,
1818
CPUBenchmarkResult,
1919
MemBenchmarkInfo,
20+
SizeBenchmarkInfo,
2021
StartupBenchmarkInfo,
2122
} from "./benchmarksCommon.js";
2223
import { StartupBenchmarkResult } from "./benchmarksLighthouse.js";
2324
import { writeResults } from "./writeResults.js";
2425
import { PlausibilityCheck } from "./timeline.js";
26+
import { SizeBenchmarkResult } from "./benchmarksSize.js";
2527

2628
function forkAndCallBenchmark(
2729
framework: FrameworkData,
2830
benchmarkInfo: BenchmarkInfo,
2931
benchmarkOptions: BenchmarkOptions
30-
): Promise<ErrorAndWarning<number | CPUBenchmarkResult | StartupBenchmarkResult>> {
32+
): Promise<ErrorAndWarning<number | CPUBenchmarkResult | StartupBenchmarkResult | SizeBenchmarkResult>> {
3133
return new Promise((resolve, reject) => {
3234
let forkedRunner = null;
3335
if (benchmarkInfo.type === BenchmarkType.STARTUP_MAIN) {
3436
forkedRunner = "dist/forkedBenchmarkRunnerLighthouse.js";
37+
} else if (benchmarkInfo.type === BenchmarkType.SIZE_MAIN) {
38+
forkedRunner = "dist/forkedBenchmarkRunnerSize.js";
3539
} else if (config.BENCHMARK_RUNNER == BenchmarkRunner.WEBDRIVER_CDP) {
3640
forkedRunner = "dist/forkedBenchmarkRunnerWebdriverCDP.js";
3741
} else if (config.BENCHMARK_RUNNER == BenchmarkRunner.PLAYWRIGHT) {
@@ -119,6 +123,51 @@ async function runBenchmakLoopStartup(
119123
// return executeBenchmark(frameworks, keyed, frameworkName, benchmarkName, benchmarkOptions);
120124
}
121125

126+
async function runBenchmakLoopSize(
127+
framework: FrameworkData,
128+
benchmarkInfo: SizeBenchmarkInfo,
129+
benchmarkOptions: BenchmarkOptions
130+
): Promise<{ errors: string[]; warnings: string[] }> {
131+
let warnings: string[] = [];
132+
let errors: string[] = [];
133+
134+
let results: Array<SizeBenchmarkResult> = [];
135+
let count = benchmarkOptions.numIterationsForSizeBenchmark;
136+
benchmarkOptions.batchSize = 1;
137+
138+
let retries = 0;
139+
let done = 0;
140+
141+
console.log("runBenchmakLoopSize", framework, benchmarkInfo);
142+
143+
while (done < count) {
144+
console.log("FORKING:", benchmarkInfo.id, "BatchSize", benchmarkOptions.batchSize);
145+
let res = await forkAndCallBenchmark(framework, benchmarkInfo, benchmarkOptions);
146+
if (Array.isArray(res.result)) {
147+
results = results.concat(res.result as SizeBenchmarkResult[]);
148+
} else {
149+
results.push(res.result);
150+
}
151+
warnings = warnings.concat(res.warnings);
152+
if (res.error) {
153+
errors.push(`Executing ${framework.uri} and benchmark ${benchmarkInfo.id} failed: ` + res.error);
154+
}
155+
done++;
156+
}
157+
console.log("******* result", results);
158+
if (config.WRITE_RESULTS) {
159+
await writeResults(benchmarkOptions.resultsDirectory, {
160+
framework: framework,
161+
benchmark: benchmarkInfo,
162+
results: results,
163+
type: BenchmarkType.SIZE,
164+
});
165+
}
166+
return { errors, warnings };
167+
// } else {
168+
// return executeBenchmark(frameworks, keyed, frameworkName, benchmarkName, benchmarkOptions);
169+
}
170+
122171
async function runBenchmakLoop(
123172
framework: FrameworkData,
124173
benchmarkInfo: CPUBenchmarkInfo | MemBenchmarkInfo,
@@ -233,6 +282,12 @@ async function runBench(
233282
benchmarkInfos[j] as StartupBenchmarkInfo,
234283
benchmarkOptions
235284
);
285+
} else if (benchmarkInfos[j].type == BenchmarkType.SIZE_MAIN) {
286+
result = await runBenchmakLoopSize(
287+
runFrameworks[i],
288+
benchmarkInfos[j] as SizeBenchmarkInfo,
289+
benchmarkOptions
290+
);
236291
} else if (benchmarkInfos[j].type == BenchmarkType.CPU) {
237292
result = await runBenchmakLoop(
238293
runFrameworks[i],
@@ -345,6 +400,7 @@ async function main() {
345400
config.NUM_ITERATIONS_FOR_BENCHMARK_CPU + config.NUM_ITERATIONS_FOR_BENCHMARK_CPU_DROP_SLOWEST_COUNT,
346401
numIterationsForMemBenchmarks: config.NUM_ITERATIONS_FOR_BENCHMARK_MEM,
347402
numIterationsForStartupBenchmark: config.NUM_ITERATIONS_FOR_BENCHMARK_STARTUP,
403+
numIterationsForSizeBenchmark: config.NUM_ITERATIONS_FOR_BENCHMARK_SIZE,
348404
batchSize: 1,
349405
resultsDirectory: "results",
350406
tracesDirectory: "traces",

webdriver-ts/src/benchmarksCommon.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export enum BenchmarkType {
55
MEM,
66
STARTUP_MAIN,
77
STARTUP,
8+
SIZE_MAIN,
9+
SIZE,
810
}
911

1012
export interface BenchmarkInfoBase {
@@ -25,6 +27,19 @@ export interface MemBenchmarkInfo extends BenchmarkInfoBase {
2527
type: BenchmarkType.MEM;
2628
}
2729

30+
export interface SizeInfoJSON {
31+
size_uncompressed: number,
32+
size_compressed: number,
33+
}
34+
35+
export interface SizeBenchmarkInfo extends BenchmarkInfoBase {
36+
type: BenchmarkType.SIZE;
37+
fn(sizeInfo: SizeInfoJSON): number;
38+
}
39+
40+
export interface SizeMainBenchmarkInfo extends BenchmarkInfoBase {
41+
type: BenchmarkType.SIZE_MAIN;
42+
}
2843
export interface StartupMainBenchmarkInfo extends BenchmarkInfoBase {
2944
type: BenchmarkType.STARTUP_MAIN;
3045
}
@@ -35,7 +50,7 @@ export interface StartupBenchmarkInfo extends BenchmarkInfoBase {
3550
fn: (x: number) => number;
3651
}
3752

38-
export type BenchmarkInfo = CPUBenchmarkInfo | MemBenchmarkInfo | StartupMainBenchmarkInfo | StartupBenchmarkInfo;
53+
export type BenchmarkInfo = CPUBenchmarkInfo | MemBenchmarkInfo | StartupMainBenchmarkInfo | StartupBenchmarkInfo | SizeBenchmarkInfo | SizeMainBenchmarkInfo;
3954

4055
export interface BenchmarkImpl {
4156
benchmarkInfo: BenchmarkInfo;
@@ -68,6 +83,7 @@ export enum Benchmark {
6883
_25 = "25_run-clear-memory",
6984
_26 = "26_run-10k-memory",
7085
_30 = "30_startup",
86+
_40 = "40_sizes",
7187
}
7288

7389
export type BenchmarkId =
@@ -80,7 +96,8 @@ export type BenchmarkId =
8096
| typeof Benchmark._07
8197
| typeof Benchmark._08
8298
| typeof Benchmark._09
83-
| typeof Benchmark._30;
99+
| typeof Benchmark._30
100+
| typeof Benchmark._40;
84101

85102
const throttlingFactors: { [idx: string]: number } = {
86103
[Benchmark._03]: 4,
@@ -237,6 +254,15 @@ export const startupBenchmarkInfosArray: Array<StartupMainBenchmarkInfo> = [
237254
type: BenchmarkType.STARTUP_MAIN,
238255
label: "",
239256
description: () => "",
257+
}
258+
];
259+
260+
export const sizesBenchmarkInfosArray: Array<SizeMainBenchmarkInfo> = [
261+
{
262+
id: Benchmark._40,
263+
type: BenchmarkType.SIZE_MAIN,
264+
label: "",
265+
description: () => "",
240266
},
241267
];
242268

@@ -255,4 +281,9 @@ for (let bi of startupBenchmarkInfosArray) {
255281
startupBenchmarkInfos[bi.id] = bi;
256282
}
257283

258-
export const benchmarkInfos = [...cpuBenchmarkInfosArray, ...memBenchmarkInfosArray, ...startupBenchmarkInfosArray];
284+
export const sizeBenchmarkInfos: { [idx: string]: SizeMainBenchmarkInfo } = {};
285+
for (let bi of sizesBenchmarkInfosArray) {
286+
sizeBenchmarkInfos[bi.id] = bi;
287+
}
288+
289+
export const benchmarkInfos = [...cpuBenchmarkInfosArray, ...memBenchmarkInfosArray, ...startupBenchmarkInfosArray, ...sizesBenchmarkInfosArray];

webdriver-ts/src/benchmarksLighthouse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as benchmarksCommon from "./benchmarksCommon.js";
22
import { BenchmarkImpl, BenchmarkType, StartupBenchmarkInfo } from "./benchmarksCommon.js";
33

4-
export interface StartupBenchmarkResult extends BenchmarkImpl {
4+
export interface StartupBenchmarkResult {
55
benchmark: StartupBenchmarkInfo;
66
result: number;
77
}

webdriver-ts/src/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface BenchmarkOptions {
3838
numIterationsForCPUBenchmarks: number;
3939
numIterationsForMemBenchmarks: number;
4040
numIterationsForStartupBenchmark: number;
41+
numIterationsForSizeBenchmark: number;
4142

4243
allowThrottling: boolean;
4344
resultsDirectory: string;
@@ -64,6 +65,7 @@ export let config = {
6465
NUM_ITERATIONS_FOR_BENCHMARK_CPU_DROP_SLOWEST_COUNT: 0, // drop the # of slowest results
6566
NUM_ITERATIONS_FOR_BENCHMARK_MEM: 1,
6667
NUM_ITERATIONS_FOR_BENCHMARK_STARTUP: 1,
68+
NUM_ITERATIONS_FOR_BENCHMARK_SIZE: 1,
6769
WARMUP_COUNT: 5,
6870
TIMEOUT: 60 * 1000,
6971
LOG_PROGRESS: true,

webdriver-ts/src/createResultJS.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ let benchmarkOptions: BenchmarkOptions = {
3434
config.NUM_ITERATIONS_FOR_BENCHMARK_CPU_DROP_SLOWEST_COUNT,
3535
numIterationsForMemBenchmarks: config.NUM_ITERATIONS_FOR_BENCHMARK_MEM,
3636
numIterationsForStartupBenchmark: config.NUM_ITERATIONS_FOR_BENCHMARK_STARTUP,
37+
numIterationsForSizeBenchmark: config.NUM_ITERATIONS_FOR_BENCHMARK_SIZE,
3738
batchSize: 1,
3839
resultsDirectory: "results",
3940
tracesDirectory: "traces",

webdriver-ts/src/forkedBenchmarkRunnerLighthouse.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@ async function runLighthouse(
6161
}
6262
if (config.LOG_DEBUG) console.log("lighthouse result", results);
6363

64-
return startupBenchmarks.map((bench) => {
65-
return {
64+
return startupBenchmarks.map((bench) => ({
6665
benchmark: bench,
6766
result: bench.fn(extractRawValue(results.lhr, bench.property)),
68-
} as StartupBenchmarkResult;
69-
});
67+
}));
7068
} catch (error) {
7169
console.log("error running lighthouse", error);
7270
throw error;

webdriver-ts/src/isCSPCompliant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ let benchmarkOptions: BenchmarkOptions = {
2929
config.NUM_ITERATIONS_FOR_BENCHMARK_CPU + config.NUM_ITERATIONS_FOR_BENCHMARK_CPU_DROP_SLOWEST_COUNT,
3030
numIterationsForMemBenchmarks: config.NUM_ITERATIONS_FOR_BENCHMARK_MEM,
3131
numIterationsForStartupBenchmark: config.NUM_ITERATIONS_FOR_BENCHMARK_STARTUP,
32+
numIterationsForSizeBenchmark: config.NUM_ITERATIONS_FOR_BENCHMARK_SIZE,
3233
batchSize: 1,
3334
resultsDirectory: "results",
3435
tracesDirectory: "traces",

webdriver-ts/src/isKeyed.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ let benchmarkOptions: BenchmarkOptions = {
3232
config.NUM_ITERATIONS_FOR_BENCHMARK_CPU + config.NUM_ITERATIONS_FOR_BENCHMARK_CPU_DROP_SLOWEST_COUNT,
3333
numIterationsForMemBenchmarks: config.NUM_ITERATIONS_FOR_BENCHMARK_MEM,
3434
numIterationsForStartupBenchmark: config.NUM_ITERATIONS_FOR_BENCHMARK_STARTUP,
35+
numIterationsForSizeBenchmark: config.NUM_ITERATIONS_FOR_BENCHMARK_SIZE,
3536
batchSize: 1,
3637
resultsDirectory: "results",
3738
tracesDirectory: "traces",

webdriver-ts/src/parseTrace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ async function debugAll() {
3535
config.NUM_ITERATIONS_FOR_BENCHMARK_CPU + config.NUM_ITERATIONS_FOR_BENCHMARK_CPU_DROP_SLOWEST_COUNT,
3636
numIterationsForMemBenchmarks: config.NUM_ITERATIONS_FOR_BENCHMARK_MEM,
3737
numIterationsForStartupBenchmark: config.NUM_ITERATIONS_FOR_BENCHMARK_STARTUP,
38+
numIterationsForSizeBenchmark: config.NUM_ITERATIONS_FOR_BENCHMARK_SIZE,
3839
batchSize: 1,
3940
resultsDirectory: "results",
4041
tracesDirectory: "traces",

webdriver-ts/src/writeResults.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import * as fs from "node:fs";
22
import { BenchmarkInfo, BenchmarkType, CPUBenchmarkResult, fileName } from "./benchmarksCommon.js";
3-
import { StartupBenchmarkResult, subbenchmarks } from "./benchmarksLighthouse.js";
3+
import * as benchmarksLighthouse from "./benchmarksLighthouse.js";
4+
import * as benchmarksSize from "./benchmarksSize.js";
45
import { FrameworkData, JsonResult, JsonResultData } from "./common.js";
56
import { stats } from "./stats.js";
67

78
export type ResultLightHouse = {
89
framework: FrameworkData;
910
benchmark: BenchmarkInfo;
10-
results: StartupBenchmarkResult[];
11+
results: benchmarksLighthouse.StartupBenchmarkResult[];
1112
type: BenchmarkType.STARTUP;
1213
};
1314

@@ -25,10 +26,23 @@ export type ResultMem = {
2526
type: BenchmarkType.MEM;
2627
};
2728

28-
export function writeResults(resultDir: string, res: ResultLightHouse | ResultCPU | ResultMem) {
29+
export type ResultSize = {
30+
framework: FrameworkData;
31+
benchmark: BenchmarkInfo;
32+
results: benchmarksSize.SizeBenchmarkResult[];
33+
type: BenchmarkType.SIZE;
34+
};
35+
36+
export function writeResults(resultDir: string, res: ResultLightHouse | ResultCPU | ResultMem | ResultSize) {
2937
switch (res.type) {
3038
case BenchmarkType.STARTUP:
31-
for (let subbench of subbenchmarks) {
39+
for (let subbench of benchmarksLighthouse.subbenchmarks) {
40+
let results = res.results.filter((r) => r.benchmark.id == subbench.id).map((r) => r.result);
41+
createResultFile(resultDir, results, res.framework, subbench);
42+
}
43+
break;
44+
case BenchmarkType.SIZE:
45+
for (let subbench of benchmarksSize.subbenchmarks) {
3246
let results = res.results.filter((r) => r.benchmark.id == subbench.id).map((r) => r.result);
3347
createResultFile(resultDir, results, res.framework, subbench);
3448
}
@@ -64,6 +78,9 @@ function createResultFile(
6478
case BenchmarkType.STARTUP:
6579
type = "startup";
6680
break;
81+
case BenchmarkType.SIZE:
82+
type = "size";
83+
break;
6784
}
6885
let convertResult = (label: string, data: number[]) => {
6986
let res = stats(data);

0 commit comments

Comments
 (0)