Changeset 225752 in webkit
- Timestamp:
- Dec 11, 2017 11:41:46 AM (6 years ago)
- Location:
- trunk/PerformanceTests
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/PerformanceTests/ChangeLog
r225698 r225752 1 2017-12-11 Antti Koivisto <antti@apple.com> 2 3 StyleBench improvements 4 https://bugs.webkit.org/show_bug.cgi?id=180646 5 6 Reviewed by Geoffrey Garen. 7 8 - Remove :empty rule from global stylesheet. It caused all tests to hit positional pseudo-class code paths. 9 - Instead use min-width to create easy flexible layout. Use it for ::before/::after too. 10 - Add :empty to positional pseudo-class test. 11 - Include some id attributes and id selectors 12 - Chance to have more than 1 classes per compound selector 13 - Change distribution of elements and classes to be non-uniform 14 - Other bug fixes 15 16 * StyleBench/resources/style-bench.js: 17 (Random.prototype.numberSquareWeightedToLow): 18 (Random): 19 (defaultConfiguration): 20 (prototype.randomElementName): 21 (prototype.randomId): 22 (prototype.makeCompoundSelector): 23 (prototype.makeSelector): 24 (prototype.makeElement): 25 1 26 2017-12-08 Konstantin Tokarev <annulen@yandex.ru> 2 27 -
trunk/PerformanceTests/StyleBench/index.html
r225324 r225752 3 3 <head> 4 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <title>StyleBench 0. 1</title>5 <title>StyleBench 0.2</title> 6 6 <link rel="stylesheet" href="../Speedometer/resources/main.css"> 7 7 <script src="../Speedometer/resources/main.js" defer></script> -
trunk/PerformanceTests/StyleBench/resources/style-bench.js
r225324 r225752 13 13 } 14 14 15 underOne() 16 { 17 return (this.next % 1048576) / 1048576; 18 } 19 15 20 chance(chance) 16 21 { 17 return this. next % 1048576 < chance * 1048576;22 return this.underOne() < chance; 18 23 } 19 24 … … 21 26 { 22 27 return this.next % under; 28 } 29 30 numberSquareWeightedToLow(under) 31 { 32 const random = this.underOne(); 33 const random2 = random * random; 34 return Math.floor(random2 * under); 23 35 } 24 36 } … … 36 48 name: 'Default', 37 49 elementTypeCount: 10, 50 idChance: 0.05, 38 51 elementChance: 0.5, 39 52 classCount: 200, … … 86 99 'last-of-type', 87 100 'only-of-type', 101 'empty', 88 102 ], 89 103 }); … … 111 125 { 112 126 this.configuration = configuration; 127 this.idCount = 0; 113 128 114 129 this.baseStyle = document.createElement("style"); … … 120 135 #testroot * { 121 136 display: inline-block; 122 }123 #testroot :empty {124 width:10px;125 137 height:10px; 138 min-width:10px; 126 139 } 127 140 `; … … 138 151 { 139 152 const elementTypeCount = this.configuration.elementTypeCount; 140 return `elem${ this.random.number (elementTypeCount) }`;153 return `elem${ this.random.numberSquareWeightedToLow(elementTypeCount) }`; 141 154 } 142 155 … … 144 157 { 145 158 const classCount = this.configuration.classCount; 146 return `class${ this.random.number (classCount) }`;159 return `class${ this.random.numberSquareWeightedToLow(classCount) }`; 147 160 } 148 161 … … 150 163 { 151 164 const maximum = Math.round(range * this.configuration.classCount); 152 return `class${ this.random.number (maximum) }`;165 return `class${ this.random.numberSquareWeightedToLow(maximum) }`; 153 166 } 154 167 … … 159 172 } 160 173 161 randomPseudoClass( )174 randomPseudoClass(isLast) 162 175 { 163 176 const pseudoClasses = this.configuration.pseudoClasses; 164 return pseudoClasses[this.random.number(pseudoClasses.length)] 165 } 166 167 makeSimpleSelector(index, length) 168 { 177 const pseudoClass = pseudoClasses[this.random.number(pseudoClasses.length)] 178 if (!isLast && pseudoClass == 'empty') 179 return this.randomPseudoClass(isLast); 180 return pseudoClass; 181 } 182 183 randomId() 184 { 185 const idCount = this.configuration.idChance * this.configuration.elementCount ; 186 return `id${ this.random.number(idCount) }`; 187 } 188 189 makeCompoundSelector(index, length) 190 { 191 const isFirst = index == 0; 169 192 const isLast = index == length - 1; 170 193 const usePseudoClass = this.random.chance(this.configuration.pseudoClassChance) && this.configuration.pseudoClasses.length; 171 const useElement = usePseudoClass || this.random.chance(this.configuration.elementChance); // :nth-of-type etc only make sense with element 172 const useClass = !useElement || this.random.chance(this.configuration.classChance); 194 const useId = isFirst && this.random.chance(this.configuration.idChance); 195 const useElement = !useId && (usePseudoClass || this.random.chance(this.configuration.elementChance)); // :nth-of-type etc only make sense with element 196 const useClass = !useId && (!useElement || this.random.chance(this.configuration.classChance)); 173 197 const useBeforeOrAfter = isLast && this.random.chance(this.configuration.beforeAfterChance); 174 198 let result = ""; 175 199 if (useElement) 176 200 result += this.randomElementName(); 201 if (useId) 202 result += "#" + this.randomId(); 177 203 if (useClass) { 178 // Use a smaller pool of class names on the left side of the selectors to create containers. 179 result += "." + this.randomClassNameFromRange((index + 1) / length); 204 const classCount = this.random.numberSquareWeightedToLow(2) + 1; 205 for (let i = 0; i < classCount; ++i) { 206 // Use a smaller pool of class names on the left side of the selectors to create containers. 207 result += "." + this.randomClassNameFromRange((index + 1) / length); 208 } 180 209 } 181 210 if (usePseudoClass) 182 result += ":" + this.randomPseudoClass( );211 result += ":" + this.randomPseudoClass(isLast); 183 212 if (useBeforeOrAfter) { 184 213 if (this.random.chance(0.5)) … … 193 222 { 194 223 const length = this.random.number(this.configuration.maximumSelectorLength) + 1; 195 let result = this.make SimpleSelector(0, length);196 for (let i = 0; i < length; ++i) {224 let result = this.makeCompoundSelector(0, length); 225 for (let i = 1; i < length; ++i) { 197 226 const combinator = this.randomCombinator(); 198 227 if (combinator != ' ') 199 228 result += " " + combinator; 200 result += " " + this.make SimpleSelector(i, length);229 result += " " + this.makeCompoundSelector(i, length); 201 230 } 202 231 return result; … … 213 242 214 243 if (selector.endsWith('::before') || selector.endsWith('::after')) 215 declaration += " content: ' \xa0';";244 declaration += " content: ''; min-width:5px; display:inline-block;"; 216 245 217 246 return declaration; … … 245 274 const hasClasses = this.random.chance(0.5); 246 275 if (hasClasses) { 247 const count = this.random.number (3) + 1;276 const count = this.random.numberSquareWeightedToLow(3) + 1; 248 277 for (let i = 0; i < count; ++i) 249 278 element.classList.add(this.randomClassName()); 279 } 280 const hasId = this.random.chance(this.configuration.idChance); 281 if (hasId) { 282 element.id = `id${ this.idCount }`; 283 this.idCount++; 250 284 } 251 285 return element;
Note: See TracChangeset
for help on using the changeset viewer.