1
+ import { BenchmarkType } from "./benchmarksCommon" ;
2
+ import {
3
+ testTextContains ,
4
+ testTextNotContained ,
5
+ testClassContains ,
6
+ testElementLocatedByXpath ,
7
+ testElementNotLocatedByXPath ,
8
+ testElementLocatedById ,
9
+ clickElementById ,
10
+ clickElementByXPath ,
11
+ getTextByXPath ,
12
+ } from "./webdriverCDPAccess" ;
13
+ import { Builder , WebDriver , promise , logging } from "selenium-webdriver" ;
14
+ import { config , FrameworkData } from "./common" ;
15
+ import * as benchmarksCommon from "./benchmarksCommon" ;
16
+ import { slowDownFactor , slowDownNote , DurationMeasurementMode } from "./benchmarksCommon" ;
17
+
18
+
19
+ const SHORT_TIMEOUT = 20 * 1000 ;
20
+
21
+ export abstract class CPUBenchmarkWebdriverCDP {
22
+ type = BenchmarkType . CPU ;
23
+ constructor ( public benchmarkInfo : benchmarksCommon . CPUBenchmark ) {
24
+ }
25
+ abstract init ( driver : WebDriver , framework : FrameworkData ) : Promise < any > ;
26
+ abstract run ( driver : WebDriver , framework : FrameworkData ) : Promise < any > ;
27
+ after ( driver : WebDriver , framework : FrameworkData ) : Promise < any > {
28
+ return null ;
29
+ }
30
+ }
31
+
32
+ export const benchRun = new ( class extends CPUBenchmarkWebdriverCDP {
33
+ constructor ( ) {
34
+ super ( {
35
+ id : benchmarksCommon . BENCHMARK_01 ,
36
+ label : "create rows" ,
37
+ description : "creating 1,000 rows" + slowDownNote ( benchmarksCommon . BENCHMARK_01 ) ,
38
+ type : BenchmarkType . CPU ,
39
+ throttleCPU : slowDownFactor ( benchmarksCommon . BENCHMARK_01 ) ,
40
+ allowBatching : true ,
41
+ durationMeasurementMode : DurationMeasurementMode . FIRST_PAINT_AFTER_LAYOUT
42
+ } ) ;
43
+ }
44
+ async init ( driver : WebDriver ) {
45
+ await testElementLocatedById ( driver , "add" , SHORT_TIMEOUT , true ) ;
46
+ }
47
+ async run ( driver : WebDriver ) {
48
+ await clickElementById ( driver , "add" , true ) ;
49
+ await testElementLocatedByXpath ( driver , "//tbody/tr[1000]/td[2]/a" , config . TIMEOUT , false ) ;
50
+ }
51
+ } ) ( ) ;
52
+
53
+ export const benchReplaceAll = new ( class extends CPUBenchmarkWebdriverCDP {
54
+ constructor ( ) {
55
+ super ( {
56
+ id : benchmarksCommon . BENCHMARK_02 ,
57
+ label : "replace all rows" ,
58
+ description : "updating all 1,000 rows (" + config . WARMUP_COUNT + " warmup runs)." + slowDownNote ( benchmarksCommon . BENCHMARK_02 ) ,
59
+ type : BenchmarkType . CPU ,
60
+ throttleCPU : slowDownFactor ( benchmarksCommon . BENCHMARK_02 ) ,
61
+ allowBatching : true ,
62
+ durationMeasurementMode : DurationMeasurementMode . FIRST_PAINT_AFTER_LAYOUT
63
+ } ) ;
64
+ }
65
+ async init ( driver : WebDriver ) {
66
+ await testElementLocatedById ( driver , "run" , SHORT_TIMEOUT , true ) ;
67
+ for ( let i = 0 ; i < config . WARMUP_COUNT ; i ++ ) {
68
+ await clickElementById ( driver , "run" , true ) ;
69
+ await testTextContains ( driver , "//tbody/tr[1]/td[1]" , ( i * 1000 + 1 ) . toFixed ( ) , config . TIMEOUT , false ) ;
70
+ }
71
+ }
72
+ async run ( driver : WebDriver ) {
73
+ await clickElementById ( driver , "run" , true ) ;
74
+ await testTextContains ( driver , "//tbody/tr[1]/td[1]" , "5001" , config . TIMEOUT , false ) ;
75
+ }
76
+ } ) ( ) ;
77
+
78
+ export const benchUpdate = new ( class extends CPUBenchmarkWebdriverCDP {
79
+ constructor ( ) {
80
+ super ( {
81
+ id : benchmarksCommon . BENCHMARK_03 ,
82
+ label : "partial update" ,
83
+ description : "updating every 10th row for 1,000 rows (3 warmup runs)." + slowDownNote ( benchmarksCommon . BENCHMARK_03 ) ,
84
+ type : BenchmarkType . CPU ,
85
+ throttleCPU : slowDownFactor ( benchmarksCommon . BENCHMARK_03 ) ,
86
+ allowBatching : true ,
87
+ durationMeasurementMode : DurationMeasurementMode . FIRST_PAINT_AFTER_LAYOUT
88
+ } ) ;
89
+ }
90
+ async init ( driver : WebDriver ) {
91
+ await testElementLocatedById ( driver , "run" , SHORT_TIMEOUT , true ) ;
92
+ await clickElementById ( driver , "run" , true ) ;
93
+ await testElementLocatedByXpath ( driver , "//tbody/tr[1000]/td[2]/a" , config . TIMEOUT , false ) ;
94
+ for ( let i = 0 ; i < 3 ; i ++ ) {
95
+ await clickElementById ( driver , "update" , true ) ;
96
+ await testTextContains ( driver , "//tbody/tr[991]/td[2]/a" , " !!!" . repeat ( i + 1 ) , config . TIMEOUT , false ) ;
97
+ }
98
+ }
99
+ async run ( driver : WebDriver ) {
100
+ await clickElementById ( driver , "update" , true ) ;
101
+ await testTextContains ( driver , "//tbody/tr[991]/td[2]/a" , " !!!" . repeat ( 3 + 1 ) , config . TIMEOUT , false ) ;
102
+ }
103
+ } ) ( ) ;
104
+
105
+ export const benchSelect = new ( class extends CPUBenchmarkWebdriverCDP {
106
+ constructor ( ) {
107
+ super ( {
108
+ id : benchmarksCommon . BENCHMARK_04 ,
109
+ label : "select row" ,
110
+ description : "highlighting a selected row. (no warmup runs)." + slowDownNote ( benchmarksCommon . BENCHMARK_04 ) ,
111
+ type : BenchmarkType . CPU ,
112
+ throttleCPU : slowDownFactor ( benchmarksCommon . BENCHMARK_04 ) ,
113
+ allowBatching : true ,
114
+ durationMeasurementMode : DurationMeasurementMode . LAST_PAINT
115
+ } ) ;
116
+ }
117
+ async init ( driver : WebDriver ) {
118
+ await testElementLocatedById ( driver , "run" , SHORT_TIMEOUT , true ) ;
119
+ await clickElementById ( driver , "run" , true ) ;
120
+ await testElementLocatedByXpath ( driver , "//tbody/tr[1]/td[2]/a" , config . TIMEOUT , false ) ;
121
+ }
122
+ async run ( driver : WebDriver ) {
123
+ await clickElementByXPath ( driver , "//tbody/tr[2]/td[2]/a" , false ) ;
124
+ await testClassContains ( driver , "//tbody/tr[2]" , "danger" , config . TIMEOUT , false ) ;
125
+ }
126
+ } ) ( ) ;
127
+
128
+ export const benchSwapRows = new ( class extends CPUBenchmarkWebdriverCDP {
129
+ constructor ( ) {
130
+ super ( {
131
+ id : benchmarksCommon . BENCHMARK_05 ,
132
+ label : "swap rows" ,
133
+ description : "swap 2 rows for table with 1,000 rows. (" + config . WARMUP_COUNT + " warmup runs)." + slowDownNote ( benchmarksCommon . BENCHMARK_05 ) ,
134
+ type : BenchmarkType . CPU ,
135
+ throttleCPU : slowDownFactor ( benchmarksCommon . BENCHMARK_05 ) ,
136
+ allowBatching : true ,
137
+ durationMeasurementMode : DurationMeasurementMode . LAST_PAINT
138
+ } ) ;
139
+ }
140
+ async init ( driver : WebDriver ) {
141
+ await testElementLocatedById ( driver , "run" , SHORT_TIMEOUT , true ) ;
142
+ await clickElementById ( driver , "run" , true ) ;
143
+ await testElementLocatedByXpath ( driver , "//tbody/tr[1]/td[2]/a" , config . TIMEOUT , false ) ;
144
+ for ( let i = 0 ; i <= config . WARMUP_COUNT ; i ++ ) {
145
+ let text = await getTextByXPath ( driver , "//tbody/tr[2]/td[2]/a" , false ) ;
146
+ await clickElementById ( driver , "swaprows" , true ) ;
147
+ await testTextContains ( driver , "//tbody/tr[999]/td[2]/a" , text , config . TIMEOUT , false ) ;
148
+ }
149
+ }
150
+ async run ( driver : WebDriver ) {
151
+ let text = await getTextByXPath ( driver , "//tbody/tr[2]/td[2]/a" , false ) ;
152
+ await clickElementById ( driver , "swaprows" , true ) ;
153
+ await testTextContains ( driver , "//tbody/tr[999]/td[2]/a" , text , config . TIMEOUT , false ) ;
154
+ }
155
+ } ) ( ) ;
156
+
157
+ export const benchRemove = new ( class extends CPUBenchmarkWebdriverCDP {
158
+ constructor ( ) {
159
+ super ( {
160
+ id : benchmarksCommon . BENCHMARK_06 ,
161
+ label : "remove row" ,
162
+ description : "removing one row. (" + config . WARMUP_COUNT + " warmup runs)." + slowDownNote ( benchmarksCommon . BENCHMARK_06 ) ,
163
+ type : BenchmarkType . CPU ,
164
+ throttleCPU : slowDownFactor ( benchmarksCommon . BENCHMARK_06 ) ,
165
+ allowBatching : true ,
166
+ durationMeasurementMode : DurationMeasurementMode . LAST_PAINT
167
+ } ) ;
168
+ }
169
+ async init ( driver : WebDriver ) {
170
+ await testElementLocatedById ( driver , "run" , SHORT_TIMEOUT , true ) ;
171
+ await clickElementById ( driver , "run" , true ) ;
172
+ await testElementLocatedByXpath ( driver , "//tbody/tr[1]/td[2]/a" , config . TIMEOUT , false ) ;
173
+ for ( let i = 0 ; i < config . WARMUP_COUNT ; i ++ ) {
174
+ await testTextContains (
175
+ driver ,
176
+ `//tbody/tr[${ config . WARMUP_COUNT - i + 4 } ]/td[1]` ,
177
+ ( config . WARMUP_COUNT - i + 4 ) . toString ( ) ,
178
+ config . TIMEOUT ,
179
+ false
180
+ ) ;
181
+ await clickElementByXPath ( driver , `//tbody/tr[${ config . WARMUP_COUNT - i + 4 } ]/td[3]/a/span[1]` , false ) ;
182
+ await testTextContains ( driver , `//tbody/tr[${ config . WARMUP_COUNT - i + 4 } ]/td[1]` , "10" , config . TIMEOUT , false ) ;
183
+ }
184
+ await testTextContains ( driver , "//tbody/tr[5]/td[1]" , "10" , config . TIMEOUT , false ) ;
185
+ await testTextContains ( driver , "//tbody/tr[4]/td[1]" , "4" , config . TIMEOUT , false ) ;
186
+
187
+ // Click on a row the second time
188
+ await testTextContains ( driver , `//tbody/tr[6]/td[1]` , "11" , config . TIMEOUT , false ) ;
189
+ await clickElementByXPath ( driver , `//tbody/tr[6]/td[3]/a/span[1]` , false ) ;
190
+ await testTextContains ( driver , `//tbody/tr[6]/td[1]` , "12" , config . TIMEOUT , false ) ;
191
+ }
192
+ async run ( driver : WebDriver ) {
193
+ await clickElementByXPath ( driver , "//tbody/tr[4]/td[3]/a/span[1]" , false ) ;
194
+ await testTextContains ( driver , "//tbody/tr[4]/td[1]" , "10" , config . TIMEOUT , false ) ;
195
+ }
196
+ } ) ( ) ;
197
+
198
+ export const benchRunBig = new ( class extends CPUBenchmarkWebdriverCDP {
199
+ constructor ( ) {
200
+ super ( {
201
+ id : benchmarksCommon . BENCHMARK_07 ,
202
+ label : "create many rows" + slowDownNote ( benchmarksCommon . BENCHMARK_07 ) ,
203
+ description : "creating 10,000 rows" ,
204
+ type : BenchmarkType . CPU ,
205
+ throttleCPU : slowDownFactor ( benchmarksCommon . BENCHMARK_07 ) ,
206
+ allowBatching : true ,
207
+ durationMeasurementMode : DurationMeasurementMode . FIRST_PAINT_AFTER_LAYOUT
208
+ } ) ;
209
+ }
210
+ async init ( driver : WebDriver ) {
211
+ await testElementLocatedById ( driver , "runlots" , SHORT_TIMEOUT , true ) ;
212
+ }
213
+ async run ( driver : WebDriver ) {
214
+ await clickElementById ( driver , "runlots" , true ) ;
215
+ await testElementLocatedByXpath ( driver , "//tbody/tr[10000]/td[2]/a" , config . TIMEOUT , false ) ;
216
+ }
217
+ } ) ( ) ;
218
+
219
+ export const benchAppendToManyRows = new ( class extends CPUBenchmarkWebdriverCDP {
220
+ constructor ( ) {
221
+ super ( {
222
+ id : benchmarksCommon . BENCHMARK_08 ,
223
+ label : "append rows to table" ,
224
+ description : "appending 1,000 to a table of 1,000 rows." + slowDownNote ( benchmarksCommon . BENCHMARK_08 ) ,
225
+ type : BenchmarkType . CPU ,
226
+ throttleCPU : slowDownFactor ( benchmarksCommon . BENCHMARK_08 ) ,
227
+ allowBatching : true ,
228
+ durationMeasurementMode : DurationMeasurementMode . FIRST_PAINT_AFTER_LAYOUT
229
+ } ) ;
230
+ }
231
+ async init ( driver : WebDriver ) {
232
+ await testElementLocatedById ( driver , "run" , SHORT_TIMEOUT , true ) ;
233
+ await clickElementById ( driver , "run" , true ) ;
234
+ await testElementLocatedByXpath ( driver , "//tbody/tr[1000]/td[2]/a" , config . TIMEOUT , false ) ;
235
+ }
236
+ async run ( driver : WebDriver ) {
237
+ await clickElementById ( driver , "add" , true ) ;
238
+ await testElementLocatedByXpath ( driver , "//tbody/tr[1100]/td[2]/a" , config . TIMEOUT , false ) ;
239
+ }
240
+ } ) ( ) ;
241
+
242
+ export const benchClear = new ( class extends CPUBenchmarkWebdriverCDP {
243
+ constructor ( ) {
244
+ super ( {
245
+ id : benchmarksCommon . BENCHMARK_09 ,
246
+ label : "clear rows" ,
247
+ description : "clearing a table with 1,000 rows." + slowDownNote ( benchmarksCommon . BENCHMARK_09 ) ,
248
+ type : BenchmarkType . CPU ,
249
+ throttleCPU : slowDownFactor ( benchmarksCommon . BENCHMARK_09 ) ,
250
+ allowBatching : true ,
251
+ durationMeasurementMode : DurationMeasurementMode . FIRST_PAINT_AFTER_LAYOUT
252
+ } ) ;
253
+ }
254
+ async init ( driver : WebDriver ) {
255
+ await testElementLocatedById ( driver , "run" , SHORT_TIMEOUT , true ) ;
256
+ await clickElementById ( driver , "run" , true ) ;
257
+ await testElementLocatedByXpath ( driver , "//tbody/tr[1000]/td[2]/a" , config . TIMEOUT , false ) ;
258
+ }
259
+ async run ( driver : WebDriver ) {
260
+ await clickElementById ( driver , "clear" , true ) ;
261
+ await testElementNotLocatedByXPath ( driver , "//tbody/tr[1]" , config . TIMEOUT , false ) ;
262
+ }
263
+ } ) ( ) ;
264
+
265
+
266
+ export function fileNameTrace ( framework : FrameworkData , benchmark : benchmarksCommon . TBenchmark , run : number ) {
267
+ return `${ config . TRACES_DIRECTORY } /${ framework . fullNameWithKeyedAndVersion } _${ benchmark . id } _${ run } .json` ;
268
+ }
0 commit comments