Skip to content

Commit 5f7e66c

Browse files
committed
add ability to run puppeteer CPU tests
1 parent e1a8370 commit 5f7e66c

17 files changed

+872
-350
lines changed

webdriver-ts/results.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as benchmarksPuppeteer from "./benchmarksPuppeteer";
2+
import * as benchmarksWebdriver from "./benchmarksWebdriver";
3+
4+
export const benchmarks: Array<benchmarksPuppeteer.BenchmarkPuppeteer|benchmarksWebdriver.BenchmarkWebdriver> = [
5+
benchmarksWebdriver.benchRun,
6+
benchmarksWebdriver.benchReplaceAll,
7+
benchmarksWebdriver.benchUpdate,
8+
benchmarksWebdriver.benchSelect,
9+
benchmarksWebdriver.benchSwapRows,
10+
benchmarksWebdriver.benchRemove,
11+
benchmarksWebdriver.benchRunBig,
12+
benchmarksWebdriver.benchAppendToManyRows,
13+
benchmarksWebdriver.benchClear,
14+
15+
benchmarksPuppeteer.benchReadyMemory,
16+
benchmarksPuppeteer.benchRunMemory,
17+
benchmarksPuppeteer.benchUpdate5Memory,
18+
benchmarksPuppeteer.benchReplace5Memory,
19+
benchmarksPuppeteer.benchCreateClear5Memory,
20+
21+
benchmarksWebdriver.benchStartup,
22+
];

webdriver-ts/src/benchmarkRunner.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import { fork } from "child_process";
22
import * as fs from "fs";
33
import * as yargs from "yargs";
4-
import { BenchmarkInfo, BenchmarkType } from "./benchmarksGeneric";
5-
import { BenchmarkPuppeteer, benchmarksPuppeteer } from "./benchmarksPuppeteer";
6-
import { benchmarksWebdriver, BenchmarkWebdriver, LighthouseData } from "./benchmarksWebdriver";
4+
import { BenchmarkInfo, BenchmarkType } from "./benchmarksCommon";
5+
import { BenchmarkPuppeteer } from "./benchmarksPuppeteer";
6+
import { BenchmarkWebdriver, LighthouseData } from "./benchmarksWebdriver";
77
import { BenchmarkOptions, config, ErrorAndWarning, FrameworkData, initializeFrameworks } from "./common";
88
import { writeResults } from "./writeResults";
9+
import {benchmarks} from "./benchmarkConfiguration";
910

1011
function forkAndCallBenchmark(
1112
framework: FrameworkData,
1213
benchmark: BenchmarkInfo,
1314
benchmarkOptions: BenchmarkOptions
1415
): Promise<ErrorAndWarning> {
1516
return new Promise((resolve, reject) => {
16-
const forked = fork(
17-
benchmark.type == BenchmarkType.MEM ? "dist/forkedBenchmarkRunnerPuppeteer.js" : "dist/forkedBenchmarkRunnerWebdriver.js"
18-
);
17+
let forkedRunner = null;
18+
if (benchmarks.some(b => b.benchmarkInfo.id == benchmark.id && b instanceof BenchmarkPuppeteer)) {
19+
forkedRunner = "dist/forkedBenchmarkRunnerPuppeteer.js";
20+
} else {
21+
forkedRunner = "dist/forkedBenchmarkRunnerWebdriver.js";
22+
}
23+
console.log("forking ",forkedRunner);
24+
const forked = fork(forkedRunner);
1925
if (config.LOG_DETAILS) console.log("FORKING: forked child process");
2026
forked.send({
2127
config,
@@ -87,7 +93,7 @@ async function runBenchmakLoop(
8793
}
8894
}
8995
if (benchmark.type == BenchmarkType.CPU) {
90-
// console.log("CPU results before: ", results);
96+
console.log("CPU results before: ", results);
9197
(results as number[]).sort((a: number, b: number) => a - b);
9298
results = results.slice(0, config.NUM_ITERATIONS_FOR_BENCHMARK_CPU);
9399
// console.log("CPU results after: ", results)
@@ -109,13 +115,9 @@ async function runBench(runFrameworks: FrameworkData[], benchmarkNames: string[]
109115
let errors: String[] = [];
110116
let warnings: String[] = [];
111117

112-
let b1: Array<BenchmarkWebdriver | BenchmarkPuppeteer> = benchmarksWebdriver.filter((b) =>
118+
let runBenchmarks: Array<BenchmarkWebdriver | BenchmarkPuppeteer> = benchmarks.filter((b) =>
113119
benchmarkNames.some((name) => b.id.toLowerCase().indexOf(name) > -1)
114120
);
115-
let b2: Array<BenchmarkWebdriver | BenchmarkPuppeteer> = benchmarksPuppeteer.filter((b) =>
116-
benchmarkNames.some((name) => b.id.toLowerCase().indexOf(name) > -1)
117-
);
118-
let runBenchmarks: Array<BenchmarkWebdriver | BenchmarkPuppeteer> = b1.concat(b2);
119121

120122
let restart: string = undefined;
121123
let index = runFrameworks.findIndex((f) => f.fullNameWithKeyedAndVersion === restart);
@@ -132,6 +134,8 @@ async function runBench(runFrameworks: FrameworkData[], benchmarkNames: string[]
132134
runBenchmarks.map((b) => b.id)
133135
);
134136

137+
console.log("HEADLESS*** ", args.headless);
138+
135139
let benchmarkOptions: BenchmarkOptions = {
136140
port: config.PORT.toFixed(),
137141
remoteDebuggingPort: config.REMOTE_DEBUGGING_PORT,
@@ -188,7 +192,7 @@ let args: any = yargs(process.argv)
188192
"$0 [--framework Framework1 Framework2 ...] [--benchmark Benchmark1 Benchmark2 ...] [--chromeBinary path] \n or: $0 [directory1] [directory2] .. [directory3]"
189193
)
190194
.help("help")
191-
.boolean("headless")
195+
.boolean("headless").default("headless", false)
192196
.boolean("smoketest")
193197
.array("framework")
194198
.array("benchmark")
@@ -218,6 +222,7 @@ async function main() {
218222
}
219223

220224
if (!fs.existsSync(config.RESULTS_DIRECTORY)) fs.mkdirSync(config.RESULTS_DIRECTORY);
225+
if (!fs.existsSync(config.TRACES_DIRECTORY)) fs.mkdirSync(config.TRACES_DIRECTORY);
221226

222227
if (args.help) {
223228
yargs.showHelp();

webdriver-ts/src/benchmarksCommon.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { FrameworkData } from "./common";
2+
3+
export enum BenchmarkType {
4+
CPU,
5+
MEM,
6+
STARTUP,
7+
}
8+
9+
export enum DurationMeasurementMode {
10+
FIRST_PAINT_AFTER_LAYOUT,
11+
LAST_PAINT
12+
}
13+
14+
export interface BenchmarkInfo {
15+
id: string;
16+
type: BenchmarkType;
17+
label: string;
18+
description: string;
19+
throttleCPU?: number;
20+
allowBatching: boolean;
21+
durationMeasurementMode: DurationMeasurementMode;
22+
}
23+
24+
export function fileName(framework: FrameworkData, benchmark: BenchmarkInfo) {
25+
return `${framework.fullNameWithKeyedAndVersion}_${benchmark.id}.json`;
26+
}
27+
28+
29+
export const BENCHMARK_01 = "01_run1k";
30+
export const BENCHMARK_02 = "02_replace1k";
31+
export const BENCHMARK_03 = "03_update10th1k_x16";
32+
export const BENCHMARK_04 = "04_select1k";
33+
export const BENCHMARK_05 = "05_swap1k";
34+
export const BENCHMARK_06 = "06_remove-one-1k";
35+
export const BENCHMARK_07 = "07_create10k";
36+
export const BENCHMARK_08 = "08_create1k-after1k_x2";
37+
export const BENCHMARK_09 = "09_clear1k_x8";
38+
39+
export const BENCHMARK_21 = "21_ready-memory";
40+
export const BENCHMARK_22 = "22_run-memory";
41+
export const BENCHMARK_23 = "23_update5-memory";
42+
export const BENCHMARK_24 = "24_run5-memory";
43+
export const BENCHMARK_25 = "25_run-clear-memory";
44+
45+
export const BENCHMARK_31 = "31_startup-ci";
46+
47+
export type TBenchmarkID =
48+
| typeof BENCHMARK_01
49+
| typeof BENCHMARK_02
50+
| typeof BENCHMARK_03
51+
| typeof BENCHMARK_04
52+
| typeof BENCHMARK_05
53+
| typeof BENCHMARK_06
54+
| typeof BENCHMARK_07
55+
| typeof BENCHMARK_08
56+
| typeof BENCHMARK_09
57+
| typeof BENCHMARK_31;
58+
59+
type ISlowDowns = {
60+
[key in TBenchmarkID]?: number;
61+
};
62+
63+
const slowDownsOSX: ISlowDowns = {
64+
[BENCHMARK_03]: 2,
65+
[BENCHMARK_04]: 4,
66+
[BENCHMARK_05]: 2,
67+
[BENCHMARK_09]: 2,
68+
};
69+
70+
const slowDownsLinux: ISlowDowns = {
71+
[BENCHMARK_03]: 16,
72+
[BENCHMARK_04]: 16,
73+
[BENCHMARK_05]: 4,
74+
[BENCHMARK_08]: 2,
75+
[BENCHMARK_09]: 8,
76+
};
77+
78+
const slowDowns: ISlowDowns = process.platform == "darwin" ? slowDownsOSX : slowDownsLinux;
79+
80+
export function slowDownNote(benchmark: TBenchmarkID): string {
81+
return slowDowns[benchmark] ? " " + slowDowns[benchmark] + "x CPU slowdown." : "";
82+
}
83+
84+
export function slowDownFactor(benchmark: TBenchmarkID): number | undefined {
85+
return slowDowns[benchmark] ? slowDowns[benchmark] : undefined;
86+
}

webdriver-ts/src/benchmarksGeneric.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)