Changeset 228237 in webkit
- Timestamp:
- Feb 7, 2018, 11:33:27 AM (7 years ago)
- Location:
- trunk/PerformanceTests
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/PerformanceTests/ChangeLog
r228023 r228237 1 2018-02-01 Antti Koivisto <antti@apple.com> 2 3 StyleBench: Attribute selectors and other improvements 4 https://bugs.webkit.org/show_bug.cgi?id=182387 5 6 Reviewed by Joseph Pecoraro. 7 8 - Add some attributes to elements in all tests 9 - Add some attribute selectors to stylesheets in all tests 10 - Also add some * selectors to all stylesheets. 11 - Add attribute mutation step to all suites 12 - Make test steps do more mutations (25->100) and reduce the number of steps to keep testing time in check. 13 Too fast steps were running into timer resolution limits. 14 15 * StyleBench/resources/style-bench.js: 16 (defaultConfiguration): 17 (prototype.randomAttributeName): 18 (prototype.randomAttributeValue): 19 (prototype.randomAttributeSelector): 20 (prototype.makeCompoundSelector): 21 (prototype.makeElement): 22 (prototype.addClasses): 23 (prototype.removeClasses): 24 (prototype.mutateAttributes): 25 (prototype.async.runForever): 26 * StyleBench/resources/tests.js: 27 (makeSteps): 28 (makeSuite): 29 1 30 2018-02-01 Geoffrey Garen <ggaren@apple.com> 2 31 -
trunk/PerformanceTests/StyleBench/resources/style-bench.js
r227769 r228237 52 52 classCount: 200, 53 53 classChance: 0.3, 54 starChance: 0.05, 55 attributeChance: 0.02, 56 attributeCount: 10, 57 attributeValueCount: 20, 58 attributeOperators: ['','='], 59 elementClassChance: 0.5, 60 elementMaximumClasses: 3, 61 elementAttributeChance: 0.2, 62 elementMaximumAttributes: 3, 54 63 combinators: [' ', '>',], 55 64 pseudoClasses: [], … … 63 72 repeatingSequenceChance: 0.2, 64 73 repeatingSequenceMaximumLength: 3, 65 leaf ClassMutationChance: 0.1,74 leafMutationChance: 0.1, 66 75 styleSeed: 1, 67 76 domSeed: 2, 77 stepCount: 5, 78 mutationsPerStep: 100, 68 79 }; 69 80 } … … 177 188 } 178 189 190 randomAttributeName() 191 { 192 const attributeCount = this.configuration.attributeCount; 193 return `attr${ this.random.numberSquareWeightedToLow(attributeCount) }`; 194 } 195 196 randomAttributeValue() 197 { 198 const attributeValueCount = this.configuration.attributeValueCount; 199 const valueNum = this.random.numberSquareWeightedToLow(attributeValueCount); 200 if (valueNum == 0) 201 return ""; 202 if (valueNum == 1) 203 return "val"; 204 return `val${valueNum}`; 205 } 206 179 207 randomCombinator() 180 208 { … … 198 226 } 199 227 228 randomAttributeSelector() 229 { 230 const name = this.randomAttributeName(); 231 const operators = this.configuration.attributeOperators; 232 const operator = operators[this.random.numberSquareWeightedToLow(operators.length)]; 233 if (operator == '') 234 return `[${name}]`; 235 const value = this.randomAttributeValue(); 236 return `[${name}${operator}"${value}"]`; 237 } 238 200 239 makeCompoundSelector(index, length) 201 240 { … … 205 244 const useId = isFirst && this.random.chance(this.configuration.idChance); 206 245 const useElement = !useId && (usePseudoClass || this.random.chance(this.configuration.elementChance)); // :nth-of-type etc only make sense with element 207 const useClass = !useId && (!useElement || this.random.chance(this.configuration.classChance)); 246 const useAttribute = !useId && this.random.chance(this.configuration.attributeChance); 247 const useIdElementOrAttribute = useId || useElement || useAttribute; 248 const useStar = !useIdElementOrAttribute && !isFirst && this.random.chance(this.configuration.starChance); 249 const useClass = !useId && !useStar && (!useIdElementOrAttribute || this.random.chance(this.configuration.classChance)); 208 250 const useBeforeOrAfter = isLast && this.random.chance(this.configuration.beforeAfterChance); 209 251 let result = ""; 210 252 if (useElement) 211 253 result += this.randomElementName(); 254 if (useStar) 255 result = "*"; 212 256 if (useId) 213 257 result += "#" + this.randomId(); … … 219 263 } 220 264 } 265 if (useAttribute) 266 result += this.randomAttributeSelector(); 267 221 268 if (usePseudoClass) 222 269 result += ":" + this.randomPseudoClass(isLast); … … 283 330 { 284 331 const element = document.createElement(this.randomElementName()); 285 const hasClasses = this.random.chance(0.5); 332 const hasClasses = this.random.chance(this.configuration.elementClassChance); 333 const hasAttributes = this.random.chance(this.configuration.elementAttributeChance); 286 334 if (hasClasses) { 287 const count = this.random.numberSquareWeightedToLow( 3) + 1;335 const count = this.random.numberSquareWeightedToLow(this.configuration.elementMaximumClasses) + 1; 288 336 for (let i = 0; i < count; ++i) 289 337 element.classList.add(this.randomClassName()); 338 } 339 if (hasAttributes) { 340 const count = this.random.number(this.configuration.elementMaximumAttributes) + 1; 341 for (let i = 0; i < count; ++i) 342 element.setAttribute(this.randomAttributeName(), this.randomAttributeValue()); 290 343 } 291 344 const hasId = this.random.chance(this.configuration.idChance); … … 366 419 const element = this.randomTreeElement(); 367 420 // There are more leaves than branches. Avoid skewing towards leaf mutations. 368 if (!element.firstChild && !this.random.chance(this.configuration.leaf ClassMutationChance))421 if (!element.firstChild && !this.random.chance(this.configuration.leafMutationChance)) 369 422 continue; 370 423 ++i; … … 379 432 const element = this.randomTreeElement(); 380 433 const classList = element.classList; 381 if (!element.firstChild && !this.random.chance(this.configuration.leaf ClassMutationChance))434 if (!element.firstChild && !this.random.chance(this.configuration.leafMutationChance)) 382 435 continue; 383 436 if (!classList.length) … … 415 468 } 416 469 this.updateCachedTestElements(); 470 } 471 472 mutateAttributes(count) 473 { 474 for (let i = 0; i < count;) { 475 const element = this.randomTreeElement(); 476 // There are more leaves than branches. Avoid skewing towards leaf mutations. 477 if (!element.firstChild && !this.random.chance(this.configuration.leafMutationChance)) 478 continue; 479 const attributeNames = element.getAttributeNames(); 480 let mutatedAttributes = false; 481 for (const name of attributeNames) { 482 if (name == "class" || name == "id") 483 continue; 484 if (this.random.chance(0.5)) 485 element.removeAttribute(name); 486 else 487 element.setAttribute(name, this.randomAttributeValue()); 488 mutatedAttributes = true; 489 } 490 if (!mutatedAttributes) { 491 const attributeCount = this.random.number(this.configuration.elementMaximumAttributes) + 1; 492 for (let j = 0; j < attributeCount; ++j) 493 element.setAttribute(this.randomAttributeName(), this.randomAttributeValue()); 494 } 495 ++i; 496 } 417 497 } 418 498 … … 424 504 this.addLeafElements(10); 425 505 this.removeLeafElements(10); 506 this.mutateAttributes(10); 426 507 427 508 await nextAnimationFrame(); -
trunk/PerformanceTests/StyleBench/resources/tests.js
r227863 r228237 1 function makeSteps(co unt)1 function makeSteps(configuration) 2 2 { 3 3 const steps = []; 4 for (i = 0; i < co unt; ++i) {4 for (i = 0; i < configuration.stepCount; ++i) { 5 5 steps.push(new BenchmarkTestStep(`Adding classes - ${i}`, (bench, contentWindow, contentDocument) => { 6 bench.addClasses( 25);6 bench.addClasses(configuration.mutationsPerStep); 7 7 })); 8 8 steps.push(new BenchmarkTestStep(`Removing classes - ${i}`, (bench, contentWindow, contentDocument) => { 9 bench.removeClasses(25); 9 bench.removeClasses(configuration.mutationsPerStep); 10 })); 11 steps.push(new BenchmarkTestStep(`Mutating attributes - ${i}`, (bench, contentWindow, contentDocument) => { 12 bench.mutateAttributes(configuration.mutationsPerStep); 10 13 })); 11 14 steps.push(new BenchmarkTestStep(`Adding leaf elements - ${i}`, (bench, contentWindow, contentDocument) => { 12 bench.addLeafElements( 25);15 bench.addLeafElements(configuration.mutationsPerStep); 13 16 })); 14 17 steps.push(new BenchmarkTestStep(`Removing leaf elements - ${i}`, (bench, contentWindow, contentDocument) => { 15 bench.removeLeafElements( 25);18 bench.removeLeafElements(configuration.mutationsPerStep); 16 19 })); 17 20 } … … 29 32 }); 30 33 }, 31 tests: makeSteps( 10),34 tests: makeSteps(configuration), 32 35 }; 33 36 }
Note:
See TracChangeset
for help on using the changeset viewer.