Skip to content

Commit a2e5483

Browse files
committed
refactor(web-ts): declare benchmark ids in enum
1 parent 7e3771e commit a2e5483

8 files changed

+154
-131
lines changed

webdriver-ts/src/benchmarksCommon.ts

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -55,43 +55,43 @@ export function fileName(framework: FrameworkData, benchmark: BenchmarkInfo) {
5555
return `${framework.fullNameWithKeyedAndVersion}_${benchmark.id}.json`;
5656
}
5757

58-
export const BENCHMARK_01 = "01_run1k";
59-
export const BENCHMARK_02 = "02_replace1k";
60-
export const BENCHMARK_03 = "03_update10th1k_x16";
61-
export const BENCHMARK_04 = "04_select1k";
62-
export const BENCHMARK_05 = "05_swap1k";
63-
export const BENCHMARK_06 = "06_remove-one-1k";
64-
export const BENCHMARK_07 = "07_create10k";
65-
export const BENCHMARK_08 = "08_create1k-after1k_x2";
66-
export const BENCHMARK_09 = "09_clear1k_x8";
67-
68-
export const BENCHMARK_21 = "21_ready-memory";
69-
export const BENCHMARK_22 = "22_run-memory";
70-
export const BENCHMARK_23 = "23_update5-memory";
71-
// export const BENCHMARK_24 = "24_run5-memory";
72-
export const BENCHMARK_25 = "25_run-clear-memory";
73-
export const BENCHMARK_26 = "26_run-10k-memory";
74-
75-
export const BENCHMARK_30 = "30_startup";
58+
export enum Benchmark {
59+
_01 = "01_run1k",
60+
_02 = "02_replace1k",
61+
_03 = "03_update10th1k_x16",
62+
_04 = "04_select1k",
63+
_05 = "05_swap1k",
64+
_06 = "06_remove-one-1k",
65+
_07 = "07_create10k",
66+
_08 = "08_create1k-after1k_x2",
67+
_09 = "09_clear1k_x8",
68+
_21 = "21_ready-memory",
69+
_22 = "22_run-memory",
70+
_23 = "23_update5-memory",
71+
// _24 = "24_run5-memory",
72+
_25 = "25_run-clear-memory",
73+
_26 = "26_run-10k-memory",
74+
_30 = "30_startup",
75+
}
7676

7777
export type BenchmarkId =
78-
| typeof BENCHMARK_01
79-
| typeof BENCHMARK_02
80-
| typeof BENCHMARK_03
81-
| typeof BENCHMARK_04
82-
| typeof BENCHMARK_05
83-
| typeof BENCHMARK_06
84-
| typeof BENCHMARK_07
85-
| typeof BENCHMARK_08
86-
| typeof BENCHMARK_09
87-
| typeof BENCHMARK_30;
78+
| typeof Benchmark._01
79+
| typeof Benchmark._02
80+
| typeof Benchmark._03
81+
| typeof Benchmark._04
82+
| typeof Benchmark._05
83+
| typeof Benchmark._06
84+
| typeof Benchmark._07
85+
| typeof Benchmark._08
86+
| typeof Benchmark._09
87+
| typeof Benchmark._30;
8888

8989
const throttlingFactors: { [idx: string]: number } = {
90-
[BENCHMARK_03]: 4,
91-
[BENCHMARK_04]: 4,
92-
[BENCHMARK_05]: 4,
93-
[BENCHMARK_06]: 2,
94-
[BENCHMARK_09]: 4,
90+
[Benchmark._03]: 4,
91+
[Benchmark._04]: 4,
92+
[Benchmark._05]: 4,
93+
[Benchmark._06]: 2,
94+
[Benchmark._09]: 4,
9595
};
9696

9797
export function slowDownNote(throttleCPU: number | undefined): string {
@@ -105,7 +105,7 @@ export function slowDownFactor(benchmarkId: string, allowThrottling: boolean): n
105105

106106
export const cpuBenchmarkInfosArray: Array<CPUBenchmarkInfo> = [
107107
{
108-
id: BENCHMARK_01,
108+
id: Benchmark._01,
109109
label: "create rows",
110110
description: (throttleCPU: number | undefined) =>
111111
"creating 1,000 rows (" + config.WARMUP_COUNT + " warmup runs)." + slowDownNote(throttleCPU),
@@ -115,7 +115,7 @@ export const cpuBenchmarkInfosArray: Array<CPUBenchmarkInfo> = [
115115
additionalNumberOfRuns: 0,
116116
},
117117
{
118-
id: BENCHMARK_02,
118+
id: Benchmark._02,
119119
label: "replace all rows",
120120
description: (throttleCPU: number | undefined) =>
121121
"updating all 1,000 rows (" +
@@ -128,7 +128,7 @@ export const cpuBenchmarkInfosArray: Array<CPUBenchmarkInfo> = [
128128
additionalNumberOfRuns: 0,
129129
},
130130
{
131-
id: BENCHMARK_03,
131+
id: Benchmark._03,
132132
label: "partial update",
133133
description: (throttleCPU: number | undefined) =>
134134
"updating every 10th row for 1,000 rows (3 warmup runs)." + slowDownNote(throttleCPU),
@@ -138,7 +138,7 @@ export const cpuBenchmarkInfosArray: Array<CPUBenchmarkInfo> = [
138138
additionalNumberOfRuns: 0,
139139
},
140140
{
141-
id: BENCHMARK_04,
141+
id: Benchmark._04,
142142
label: "select row",
143143
description: (throttleCPU: number | undefined) =>
144144
"highlighting a selected row. (" +
@@ -151,7 +151,7 @@ export const cpuBenchmarkInfosArray: Array<CPUBenchmarkInfo> = [
151151
additionalNumberOfRuns: 10,
152152
},
153153
{
154-
id: BENCHMARK_05,
154+
id: Benchmark._05,
155155
label: "swap rows",
156156
description: (throttleCPU: number | undefined) =>
157157
"swap 2 rows for table with 1,000 rows. (" +
@@ -164,7 +164,7 @@ export const cpuBenchmarkInfosArray: Array<CPUBenchmarkInfo> = [
164164
additionalNumberOfRuns: 0,
165165
},
166166
{
167-
id: BENCHMARK_06,
167+
id: Benchmark._06,
168168
label: "remove row",
169169
description: (throttleCPU: number | undefined) =>
170170
"removing one row. (" + config.WARMUP_COUNT + " warmup runs)." + slowDownNote(throttleCPU),
@@ -174,7 +174,7 @@ export const cpuBenchmarkInfosArray: Array<CPUBenchmarkInfo> = [
174174
additionalNumberOfRuns: 0,
175175
},
176176
{
177-
id: BENCHMARK_07,
177+
id: Benchmark._07,
178178
label: "create many rows",
179179
description: (throttleCPU: number | undefined) =>
180180
"creating 10,000 rows. (" +
@@ -187,7 +187,7 @@ export const cpuBenchmarkInfosArray: Array<CPUBenchmarkInfo> = [
187187
additionalNumberOfRuns: 0,
188188
},
189189
{
190-
id: BENCHMARK_08,
190+
id: Benchmark._08,
191191
label: "append rows to large table",
192192
description: (throttleCPU: number | undefined) =>
193193
"appending 1,000 to a table of 10,000 rows." + slowDownNote(throttleCPU),
@@ -197,7 +197,7 @@ export const cpuBenchmarkInfosArray: Array<CPUBenchmarkInfo> = [
197197
additionalNumberOfRuns: 0,
198198
},
199199
{
200-
id: BENCHMARK_09,
200+
id: Benchmark._09,
201201
label: "clear rows",
202202
description: (throttleCPU: number | undefined) =>
203203
"clearing a table with 1,000 rows." +
@@ -214,37 +214,37 @@ export const cpuBenchmarkInfosArray: Array<CPUBenchmarkInfo> = [
214214

215215
export const memBenchmarkInfosArray: Array<MemBenchmarkInfo> = [
216216
{
217-
id: BENCHMARK_21,
217+
id: Benchmark._21,
218218
label: "ready memory",
219219
description: () => "Memory usage after page load.",
220220
type: BenchmarkType.MEM,
221221
},
222222
{
223-
id: BENCHMARK_22,
223+
id: Benchmark._22,
224224
label: "run memory",
225225
description: () => "Memory usage after adding 1,000 rows.",
226226
type: BenchmarkType.MEM,
227227
},
228228
{
229-
id: BENCHMARK_23,
229+
id: Benchmark._23,
230230
label: "update every 10th row for 1k rows (5 cycles)",
231231
description: () => "Memory usage after clicking update every 10th row 5 times",
232232
type: BenchmarkType.MEM,
233233
},
234234
// {
235-
// id: BENCHMARK_24,
235+
// id: Benchmark._24,
236236
// label: "replace 1k rows (5 cycles)",
237237
// description: "Memory usage after clicking create 1000 rows 5 times",
238238
// type: BenchmarkType.MEM,
239239
// },
240240
{
241-
id: BENCHMARK_25,
241+
id: Benchmark._25,
242242
label: "creating/clearing 1k rows (5 cycles)",
243243
description: () => "Memory usage after creating and clearing 1000 rows 5 times",
244244
type: BenchmarkType.MEM,
245245
},
246246
{
247-
id: BENCHMARK_26,
247+
id: Benchmark._26,
248248
label: "run memory 10k",
249249
description: () => "Memory usage after adding 10,000 rows.",
250250
type: BenchmarkType.MEM,
@@ -253,7 +253,7 @@ export const memBenchmarkInfosArray: Array<MemBenchmarkInfo> = [
253253

254254
export const startupBenchmarkInfosArray: Array<StartupMainBenchmarkInfo> = [
255255
{
256-
id: BENCHMARK_30,
256+
id: Benchmark._30,
257257
type: BenchmarkType.STARTUP_MAIN,
258258
label: "",
259259
description: () => "",

webdriver-ts/src/benchmarksLighthouse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const subbenchmarks = [
5757

5858
export class BenchmarkLighthouse implements BenchmarkImpl {
5959
type = BenchmarkType.STARTUP_MAIN;
60-
benchmarkInfo = benchmarksCommon.startupBenchmarkInfos[benchmarksCommon.BENCHMARK_30];
60+
benchmarkInfo = benchmarksCommon.startupBenchmarkInfos[benchmarksCommon.Benchmark._30];
6161
subbenchmarks = subbenchmarks;
6262
}
6363

webdriver-ts/src/benchmarksPlaywright.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
// import { testTextContains, testTextContainsJS, testTextNotContained, testClassContains, testElementLocatedByXpath, testElementNotLocatedByXPath, testElementLocatedById, clickElementById, clickElementByXPath, getTextByXPath } from './webdriverAccess'
22

33
import { Browser, Page } from "playwright-core";
4-
import * as benchmarksCommon from "./benchmarksCommon.js";
5-
import { BenchmarkType } from "./benchmarksCommon.js";
4+
import {
5+
Benchmark,
6+
BenchmarkImpl,
7+
BenchmarkType,
8+
CPUBenchmarkInfo,
9+
MemBenchmarkInfo,
10+
cpuBenchmarkInfos,
11+
memBenchmarkInfos,
12+
} from "./benchmarksCommon.js";
613
import { BenchmarkOptions, config, FrameworkData } from "./common.js";
714
import {
815
checkCountForSelector,
@@ -13,16 +20,16 @@ import {
1320
clickElement,
1421
} from "./playwrightAccess.js";
1522

16-
export abstract class CPUBenchmarkPlaywright implements benchmarksCommon.BenchmarkImpl {
23+
export abstract class CPUBenchmarkPlaywright implements BenchmarkImpl {
1724
type = BenchmarkType.CPU;
18-
constructor(public benchmarkInfo: benchmarksCommon.CPUBenchmarkInfo) {}
25+
constructor(public benchmarkInfo: CPUBenchmarkInfo) {}
1926
abstract init(browser: Browser, page: Page, framework: FrameworkData): Promise<any>;
2027
abstract run(browser: Browser, page: Page, framework: FrameworkData): Promise<any>;
2128
}
2229

23-
export abstract class MemBenchmarkPlaywright implements benchmarksCommon.BenchmarkImpl {
30+
export abstract class MemBenchmarkPlaywright implements BenchmarkImpl {
2431
type = BenchmarkType.MEM;
25-
constructor(public benchmarkInfo: benchmarksCommon.MemBenchmarkInfo) {}
32+
constructor(public benchmarkInfo: MemBenchmarkInfo) {}
2633
abstract init(browser: Browser, page: Page, framework: FrameworkData): Promise<any>;
2734
abstract run(browser: Browser, page: Page, framework: FrameworkData): Promise<any>;
2835
}
@@ -31,7 +38,7 @@ export type BenchmarkPlaywright = CPUBenchmarkPlaywright | MemBenchmarkPlaywrigh
3138

3239
export let benchRun = new (class extends CPUBenchmarkPlaywright {
3340
constructor() {
34-
super(benchmarksCommon.cpuBenchmarkInfos[benchmarksCommon.BENCHMARK_01]);
41+
super(cpuBenchmarkInfos[Benchmark._01]);
3542
}
3643
async init(browser: Browser, page: Page) {
3744
await checkElementExists(page, "#run");
@@ -58,7 +65,7 @@ export let benchRun = new (class extends CPUBenchmarkPlaywright {
5865

5966
export const benchReplaceAll = new (class extends CPUBenchmarkPlaywright {
6067
constructor() {
61-
super(benchmarksCommon.cpuBenchmarkInfos[benchmarksCommon.BENCHMARK_02]);
68+
super(cpuBenchmarkInfos[Benchmark._02]);
6269
}
6370
async init(browser: Browser, page: Page) {
6471
await checkElementExists(page, "#run");
@@ -79,7 +86,7 @@ export const benchReplaceAll = new (class extends CPUBenchmarkPlaywright {
7986

8087
export const benchUpdate = new (class extends CPUBenchmarkPlaywright {
8188
constructor() {
82-
super(benchmarksCommon.cpuBenchmarkInfos[benchmarksCommon.BENCHMARK_03]);
89+
super(cpuBenchmarkInfos[Benchmark._03]);
8390
}
8491
async init(browser: Browser, page: Page) {
8592
await checkElementExists(page, "#run");
@@ -106,7 +113,7 @@ export const benchUpdate = new (class extends CPUBenchmarkPlaywright {
106113

107114
export const benchSelect = new (class extends CPUBenchmarkPlaywright {
108115
constructor() {
109-
super(benchmarksCommon.cpuBenchmarkInfos[benchmarksCommon.BENCHMARK_04]);
116+
super(cpuBenchmarkInfos[Benchmark._04]);
110117
}
111118
async init(browser: Browser, page: Page) {
112119
await checkElementExists(page, "#run");
@@ -126,7 +133,7 @@ export const benchSelect = new (class extends CPUBenchmarkPlaywright {
126133

127134
export const benchSwapRows = new (class extends CPUBenchmarkPlaywright {
128135
constructor() {
129-
super(benchmarksCommon.cpuBenchmarkInfos[benchmarksCommon.BENCHMARK_05]);
136+
super(cpuBenchmarkInfos[Benchmark._05]);
130137
}
131138
async init(browser: Browser, page: Page) {
132139
await checkElementExists(page, "#run");
@@ -147,7 +154,7 @@ export const benchSwapRows = new (class extends CPUBenchmarkPlaywright {
147154

148155
export const benchRemove = new (class extends CPUBenchmarkPlaywright {
149156
constructor() {
150-
super(benchmarksCommon.cpuBenchmarkInfos[benchmarksCommon.BENCHMARK_06]);
157+
super(cpuBenchmarkInfos[Benchmark._06]);
151158
}
152159
async init(browser: Browser, page: Page) {
153160
await checkElementExists(page, "#run");
@@ -187,7 +194,7 @@ export const benchRemove = new (class extends CPUBenchmarkPlaywright {
187194

188195
export const benchRunBig = new (class extends CPUBenchmarkPlaywright {
189196
constructor() {
190-
super(benchmarksCommon.cpuBenchmarkInfos[benchmarksCommon.BENCHMARK_07]);
197+
super(cpuBenchmarkInfos[Benchmark._07]);
191198
}
192199
async init(browser: Browser, page: Page) {
193200
await checkElementExists(page, "#run");
@@ -210,7 +217,7 @@ export const benchRunBig = new (class extends CPUBenchmarkPlaywright {
210217

211218
export const benchAppendToManyRows = new (class extends CPUBenchmarkPlaywright {
212219
constructor() {
213-
super(benchmarksCommon.cpuBenchmarkInfos[benchmarksCommon.BENCHMARK_08]);
220+
super(cpuBenchmarkInfos[Benchmark._08]);
214221
}
215222
async init(browser: Browser, page: Page) {
216223
await checkElementExists(page, "#run");
@@ -225,7 +232,7 @@ export const benchAppendToManyRows = new (class extends CPUBenchmarkPlaywright {
225232

226233
export const benchClear = new (class extends CPUBenchmarkPlaywright {
227234
constructor() {
228-
super(benchmarksCommon.cpuBenchmarkInfos[benchmarksCommon.BENCHMARK_09]);
235+
super(cpuBenchmarkInfos[Benchmark._09]);
229236
}
230237
async init(browser: Browser, page: Page) {
231238
await checkElementExists(page, "#run");
@@ -254,7 +261,7 @@ export const benchClear = new (class extends CPUBenchmarkPlaywright {
254261

255262
export const benchReadyMemory = new (class extends MemBenchmarkPlaywright {
256263
constructor() {
257-
super(benchmarksCommon.memBenchmarkInfos[benchmarksCommon.BENCHMARK_21]);
264+
super(memBenchmarkInfos[Benchmark._21]);
258265
}
259266
async init(browser: Browser, page: Page) {
260267
await checkElementExists(page, "#run");
@@ -266,7 +273,7 @@ export const benchReadyMemory = new (class extends MemBenchmarkPlaywright {
266273

267274
export const benchRunMemory = new (class extends MemBenchmarkPlaywright {
268275
constructor() {
269-
super(benchmarksCommon.memBenchmarkInfos[benchmarksCommon.BENCHMARK_22]);
276+
super(memBenchmarkInfos[Benchmark._22]);
270277
}
271278
async init(browser: Browser, page: Page) {
272279
await checkElementExists(page, "#run");
@@ -279,7 +286,7 @@ export const benchRunMemory = new (class extends MemBenchmarkPlaywright {
279286

280287
export const benchRun10KMemory = new (class extends MemBenchmarkPlaywright {
281288
constructor() {
282-
super(benchmarksCommon.memBenchmarkInfos[benchmarksCommon.BENCHMARK_26]);
289+
super(memBenchmarkInfos[Benchmark._26]);
283290
}
284291
async init(browser: Browser, page: Page) {
285292
await checkElementExists(page, "#runlots");
@@ -292,7 +299,7 @@ export const benchRun10KMemory = new (class extends MemBenchmarkPlaywright {
292299

293300
export const benchUpdate5Memory = new (class extends MemBenchmarkPlaywright {
294301
constructor() {
295-
super(benchmarksCommon.memBenchmarkInfos[benchmarksCommon.BENCHMARK_23]);
302+
super(memBenchmarkInfos[Benchmark._23]);
296303
}
297304
async init(browser: Browser, page: Page) {
298305
await checkElementExists(page, "#run");
@@ -312,7 +319,7 @@ export const benchUpdate5Memory = new (class extends MemBenchmarkPlaywright {
312319

313320
// export const benchReplace5Memory = new (class extends MemBenchmarkPlaywright {
314321
// constructor() {
315-
// super(benchmarksCommon.memBenchmarkInfos[benchmarksCommon.BENCHMARK_24]);
322+
// super(memBenchmarkInfos[Benchmark._24]);
316323
// }
317324
// async init(browser: Browser, page: Page) {
318325
// await checkElementExists(page, "#run");
@@ -327,7 +334,7 @@ export const benchUpdate5Memory = new (class extends MemBenchmarkPlaywright {
327334

328335
export const benchCreateClear5Memory = new (class extends MemBenchmarkPlaywright {
329336
constructor() {
330-
super(benchmarksCommon.memBenchmarkInfos[benchmarksCommon.BENCHMARK_25]);
337+
super(memBenchmarkInfos[Benchmark._25]);
331338
}
332339
async init(browser: Browser, page: Page) {
333340
await checkElementExists(page, "#run");

0 commit comments

Comments
 (0)