Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 new BenchmarkSuite('Values', [1000], [ | |
| 6 new Benchmark('Basic', false, false, 0, Basic, BasicSetup, BasicTearDown), | |
| 7 new Benchmark('BasicMegamorphic', false, false, 0, BasicMegamorphic, | |
| 8 BasicMegamorphicSetup, BasicMegamorphicTearDown) | |
| 9 ]); | |
| 10 | |
| 11 var object; | |
| 12 var symbol1; | |
| 13 var symbol2; | |
| 14 var result; | |
| 15 | |
| 16 function Basic() { | |
| 17 result = Object.values(object); | |
| 18 } | |
| 19 | |
| 20 | |
| 21 function BasicSetup() { | |
| 22 result = undefined; | |
| 23 symbol1 = Symbol('test'); | |
| 24 object = { a: 10 }; | |
| 25 object[26.0] = 'third'; | |
| 26 object.b = 72; | |
| 27 object[symbol1] = 'TEST'; | |
| 28 Object.defineProperty(object, 'not-enumerable', { | |
| 29 enumerable: false, value: 'nope', writable: true, configurable: true }); | |
| 30 } | |
| 31 | |
| 32 | |
| 33 function BasicTearDown() { | |
| 34 return result.length === 3 && result[0] === 10 && result[1] === 'third' && | |
| 35 result[2] === 72; | |
| 36 } | |
| 37 | |
| 38 // ---------------------------------------------------------------------------- | |
| 39 | |
| 40 function BasicMegamorphic() { | |
| 41 result = [ | |
| 42 Object.values(object[0]), Object.values(object[1]), Object.values(object[2]) , | |
| 43 Object.values(object[3]), Object.values(object[4]), Object.values(object[5]) , | |
| 44 Object.values(object[6]), Object.values(object[7]), Object.values(object[8]) , | |
| 45 Object.values(object[9]), Object.values(object[10]), Object.values(object[11 ]), | |
| 46 Object.values(object[12]), Object.values(object[13]), Object.values(object[1 4]), | |
| 47 Object.values(object[15]), Object.values(object[16]), Object.values(object[1 7]), | |
| 48 Object.values(object[18]), Object.values(object[19]), Object.values(object[2 0]), | |
| 49 Object.values(object[21]), Object.values(object[22]), Object.values(object[2 3]), | |
| 50 Object.values(object[24]), | |
| 51 Object.values(object[0]), Object.values(object[1]), Object.values(object[2]) , | |
| 52 Object.values(object[3]), Object.values(object[4]), Object.values(object[5]) , | |
| 53 Object.values(object[6]), Object.values(object[7]), Object.values(object[8]) , | |
| 54 Object.values(object[9]), Object.values(object[10]), Object.values(object[11 ]), | |
| 55 Object.values(object[12]), Object.values(object[13]), Object.values(object[1 4]), | |
| 56 Object.values(object[15]), Object.values(object[16]), Object.values(object[1 7]), | |
| 57 Object.values(object[18]), Object.values(object[19]), Object.values(object[2 0]), | |
| 58 Object.values(object[21]), Object.values(object[22]), Object.values(object[2 3]), | |
| 59 Object.values(object[24]), | |
| 60 Object.values(object[0]), Object.values(object[1]), Object.values(object[2]) , | |
| 61 Object.values(object[3]), Object.values(object[4]), Object.values(object[5]) , | |
| 62 Object.values(object[6]), Object.values(object[7]), Object.values(object[8]) , | |
| 63 Object.values(object[9]), Object.values(object[10]), Object.values(object[11 ]), | |
| 64 Object.values(object[12]), Object.values(object[13]), Object.values(object[1 4]), | |
| 65 Object.values(object[15]), Object.values(object[16]), Object.values(object[1 7]), | |
| 66 Object.values(object[18]), Object.values(object[19]), Object.values(object[2 0]), | |
| 67 Object.values(object[21]), Object.values(object[22]), Object.values(object[2 3]), | |
| 68 Object.values(object[24]), | |
| 69 Object.values(object[0]), Object.values(object[1]), Object.values(object[2]) , | |
| 70 Object.values(object[3]), Object.values(object[4]), Object.values(object[5]) , | |
| 71 Object.values(object[6]), Object.values(object[7]), Object.values(object[8]) , | |
| 72 Object.values(object[9]), Object.values(object[10]), Object.values(object[11 ]), | |
| 73 Object.values(object[12]), Object.values(object[13]), Object.values(object[1 4]), | |
| 74 Object.values(object[15]), Object.values(object[16]), Object.values(object[1 7]), | |
| 75 Object.values(object[18]), Object.values(object[19]), Object.values(object[2 0]), | |
| 76 Object.values(object[21]), Object.values(object[22]), Object.values(object[2 3]), | |
| 77 Object.values(object[24]), | |
|
Camillo Bruni
2016/03/04 17:15:25
How about something more sustainable:
var length
caitp (gmail)
2016/03/04 17:19:30
Are you sure LICM won't just turn this into a "no-
| |
| 78 ]; | |
| 79 } | |
| 80 | |
| 81 | |
| 82 function BasicMegamorphicSetup() { | |
| 83 symbol1 = Symbol('megamorphicTest'); | |
| 84 symbol2 = Symbol('megamorphicTest2'); | |
| 85 object = [ | |
| 86 { a: 1, [symbol1]: 'ignored' }, | |
| 87 { q: 'q', [symbol1]: 'ignored', zz: '2' }, | |
| 88 { precedence: 13, operator: '*', lhs: 4.7, rhs: 5.9 }, | |
| 89 { name: 'Wiggins', occupation: 'woofer', age: 4, breed: 'papillon' }, | |
| 90 { author: 'Ted Chiang', title: 'The Lifecycle Of Software Objects', | |
| 91 isbn: '978-1-59606-317-4' }, | |
| 92 { lemon_zest: true, [symbol1]: 'ignored', }, | |
| 93 { elite_status: 'zerpaderp', airline: 'Bambasherp Airways' }, | |
| 94 { card_no: 'xxxx-xxxx-xxxx-xxxx', exp_date: 'mm/dd', | |
| 95 card_holder: 'Zapp Brannigan', authorized_date: '01/02/3066' }, | |
| 96 { [symbol1]: 'ignored', a: 49 }, | |
| 97 { a: 64, [symbol1]: 'ignored', b: 45 }, | |
| 98 { a: 64, [symbol1]: 'ignored', c: 72 }, | |
| 99 { operator: '>>>', lhs: 0x8000, rhs: 2, precedence: 11 }, | |
| 100 { [symbol1]: 'ignored', lemon_zest: false, basil: true }, | |
| 101 Object.defineProperty({ a: 64, [symbol1]: 'ignored', b: 45 }, '_hidden', { | |
| 102 get() { return 'ignored!' }, | |
| 103 set() { throw new Error('NO!'); }, | |
| 104 enumerable: false, configurable: false | |
| 105 }), | |
| 106 Object.defineProperty({ exp_date: 'mm/dd', card_no: 'xxx-xxx-xxx-xxx', | |
| 107 card_holder: 'Zapp Brannigan' }, 'declined', { | |
| 108 value: '01/02/3066', | |
| 109 enumerable: true, | |
| 110 configurable: false, | |
| 111 writable: false | |
| 112 }), | |
| 113 { item: 'potato', qty: '6.7kg', date: '02/13/1947' }, | |
| 114 { date: '02/27/1948', item: 'scallop', qty: '3.4kg' }, | |
| 115 { qty: '448g', item: 'peppercorn', date: '03/17/1948', delivery: true }, | |
| 116 { number: 26, name: 'Taft, William Howard', sworn: '03/04/1909' }, | |
| 117 { name: 'Roosevelt, Franklin D', sworn: '03/04/1933', number: 32 }, | |
| 118 { [symbol2]: 'symbol2', [symbol1]: 'symbol1', token: 'collected' }, | |
| 119 { 0: 44, 1: 88, a: 49, b: 68 }, | |
| 120 { 44: 1, a: 49, c: 71 }, | |
| 121 { count: 984, year: 2016, bugs: 'fixed' }, | |
| 122 { cavities: 0, fillers: 0, cracks: 0, color: 'pristine', flosses: 'daily' } | |
| 123 ]; | |
| 124 } | |
| 125 | |
| 126 | |
| 127 function BasicMegamorphicTearDown() { | |
| 128 // TODO(caitp): move these result verifier utilities (from mjsunit.js) to | |
| 129 // base.js? Or just load mjsunit.js? | |
| 130 var ObjectPrototypeToString = Object.prototype.toString; | |
| 131 var NumberPrototypeValueOf = Number.prototype.valueOf; | |
| 132 var BooleanPrototypeValueOf = Boolean.prototype.valueOf; | |
| 133 var StringPrototypeValueOf = String.prototype.valueOf; | |
| 134 var DatePrototypeValueOf = Date.prototype.valueOf; | |
| 135 var RegExpPrototypeToString = RegExp.prototype.toString; | |
| 136 var ArrayPrototypeMap = Array.prototype.map; | |
| 137 var ArrayPrototypeJoin = Array.prototype.join; | |
| 138 | |
| 139 function classOf(object) { | |
| 140 // Argument must not be null or undefined. | |
| 141 var string = ObjectPrototypeToString.call(object); | |
| 142 // String has format [object <ClassName>]. | |
| 143 return string.substring(8, string.length - 1); | |
| 144 } | |
| 145 | |
| 146 | |
| 147 function ValueOf(value) { | |
| 148 switch (classOf(value)) { | |
| 149 case "Number": | |
| 150 return NumberPrototypeValueOf.call(value); | |
| 151 case "String": | |
| 152 return StringPrototypeValueOf.call(value); | |
| 153 case "Boolean": | |
| 154 return BooleanPrototypeValueOf.call(value); | |
| 155 case "Date": | |
| 156 return DatePrototypeValueOf.call(value); | |
| 157 default: | |
| 158 return value; | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 function deepObjectEquals(a, b) { | |
| 163 var aProps = Object.keys(a); | |
| 164 aProps.sort(); | |
| 165 var bProps = Object.keys(b); | |
| 166 bProps.sort(); | |
| 167 if (!deepEquals(aProps, bProps)) { | |
| 168 return false; | |
| 169 } | |
| 170 for (var i = 0; i < aProps.length; i++) { | |
| 171 if (!deepEquals(a[aProps[i]], b[aProps[i]])) { | |
| 172 return false; | |
| 173 } | |
| 174 } | |
| 175 return true; | |
| 176 } | |
| 177 | |
| 178 | |
| 179 function deepEquals(a, b) { | |
| 180 if (a === b) { | |
| 181 // Check for -0. | |
| 182 if (a === 0) return (1 / a) === (1 / b); | |
| 183 return true; | |
| 184 } | |
| 185 if (typeof a !== typeof b) return false; | |
| 186 if (typeof a === "number") return isNaN(a) && isNaN(b); | |
| 187 if (typeof a !== "object" && typeof a !== "function") return false; | |
| 188 // Neither a nor b is primitive. | |
| 189 var objectClass = classOf(a); | |
| 190 if (objectClass !== classOf(b)) return false; | |
| 191 if (objectClass === "RegExp") { | |
| 192 // For RegExp, just compare pattern and flags using its toString. | |
| 193 return RegExpPrototypeToString.call(a) === | |
| 194 RegExpPrototypeToString.call(b); | |
| 195 } | |
| 196 // Functions are only identical to themselves. | |
| 197 if (objectClass === "Function") return false; | |
| 198 if (objectClass === "Array") { | |
| 199 var elementCount = 0; | |
| 200 if (a.length !== b.length) { | |
| 201 return false; | |
| 202 } | |
| 203 for (var i = 0; i < a.length; i++) { | |
| 204 if (!deepEquals(a[i], b[i])) return false; | |
| 205 } | |
| 206 return true; | |
| 207 } | |
| 208 if (objectClass === "String" || objectClass === "Number" || | |
| 209 objectClass === "Boolean" || objectClass === "Date") { | |
| 210 if (ValueOf(a) !== ValueOf(b)) return false; | |
| 211 } | |
| 212 return deepObjectEquals(a, b); | |
| 213 } | |
| 214 | |
| 215 var expected = [ | |
| 216 [1], ['q', '2'], [13, '*', 4.7, 5.9], ['Wiggins', 'woofer', 4, 'papillon'], | |
| 217 ['Ted Chiang', 'The Lifecycle Of Software Objects', '978-1-59606-317-4'], | |
| 218 [true], ['zerpaderp', 'Bambasherp Airways'], | |
| 219 ['xxxx-xxxx-xxxx-xxxx', 'mm/dd', 'Zapp Brannigan', '01/02/3066'], | |
| 220 [49], [64, 45], [64, 72], ['>>>', 0x8000, 2, 11], [false, true], [64, 45], | |
| 221 ['mm/dd', 'xxx-xxx-xxx-xxx', 'Zapp Brannigan', '01/02/3066'], | |
| 222 ['potato', '6.7kg', '02/13/1947'], ['02/27/1948', 'scallop', '3.4kg'], | |
| 223 ['448g', 'peppercorn', '03/17/1948', true], | |
| 224 [26, 'Taft, William Howard', '03/04/1909'], | |
| 225 ['Roosevelt, Franklin D', '03/04/1933', 32], ['collected'], | |
| 226 [44, 88, 49, 68], [1, 49, 71], [984, 2016, 'fixed'], | |
| 227 [0, 0, 0, 'pristine', 'daily'], | |
| 228 [1], ['q', '2'], [13, '*', 4.7, 5.9], ['Wiggins', 'woofer', 4, 'papillon'], | |
| 229 ['Ted Chiang', 'The Lifecycle Of Software Objects', '978-1-59606-317-4'], | |
| 230 [true], ['zerpaderp', 'Bambasherp Airways'], | |
| 231 ['xxxx-xxxx-xxxx-xxxx', 'mm/dd', 'Zapp Brannigan', '01/02/3066'], | |
| 232 [49], [64, 45], [64, 72], ['>>>', 0x8000, 2, 11], [false, true], [64, 45], | |
| 233 ['mm/dd', 'xxx-xxx-xxx-xxx', 'Zapp Brannigan', '01/02/3066'], | |
| 234 ['potato', '6.7kg', '02/13/1947'], ['02/27/1948', 'scallop', '3.4kg'], | |
| 235 ['448g', 'peppercorn', '03/17/1948', true], | |
| 236 [26, 'Taft, William Howard', '03/04/1909'], | |
| 237 ['Roosevelt, Franklin D', '03/04/1933', 32], ['collected'], | |
| 238 [44, 88, 49, 68], [1, 49, 71], [984, 2016, 'fixed'], | |
| 239 [0, 0, 0, 'pristine', 'daily'], | |
| 240 [1], ['q', '2'], [13, '*', 4.7, 5.9], ['Wiggins', 'woofer', 4, 'papillon'], | |
| 241 ['Ted Chiang', 'The Lifecycle Of Software Objects', '978-1-59606-317-4'], | |
| 242 [true], ['zerpaderp', 'Bambasherp Airways'], | |
| 243 ['xxxx-xxxx-xxxx-xxxx', 'mm/dd', 'Zapp Brannigan', '01/02/3066'], | |
| 244 [49], [64, 45], [64, 72], ['>>>', 0x8000, 2, 11], [false, true], [64, 45], | |
| 245 ['mm/dd', 'xxx-xxx-xxx-xxx', 'Zapp Brannigan', '01/02/3066'], | |
| 246 ['potato', '6.7kg', '02/13/1947'], ['02/27/1948', 'scallop', '3.4kg'], | |
| 247 ['448g', 'peppercorn', '03/17/1948', true], | |
| 248 [26, 'Taft, William Howard', '03/04/1909'], | |
| 249 ['Roosevelt, Franklin D', '03/04/1933', 32], ['collected'], | |
| 250 [44, 88, 49, 68], [1, 49, 71], [984, 2016, 'fixed'], | |
| 251 [0, 0, 0, 'pristine', 'daily'], | |
| 252 [1], ['q', '2'], [13, '*', 4.7, 5.9], ['Wiggins', 'woofer', 4, 'papillon'], | |
| 253 ['Ted Chiang', 'The Lifecycle Of Software Objects', '978-1-59606-317-4'], | |
| 254 [true], ['zerpaderp', 'Bambasherp Airways'], | |
| 255 ['xxxx-xxxx-xxxx-xxxx', 'mm/dd', 'Zapp Brannigan', '01/02/3066'], | |
| 256 [49], [64, 45], [64, 72], ['>>>', 0x8000, 2, 11], [false, true], [64, 45], | |
| 257 ['mm/dd', 'xxx-xxx-xxx-xxx', 'Zapp Brannigan', '01/02/3066'], | |
| 258 ['potato', '6.7kg', '02/13/1947'], ['02/27/1948', 'scallop', '3.4kg'], | |
| 259 ['448g', 'peppercorn', '03/17/1948', true], | |
| 260 [26, 'Taft, William Howard', '03/04/1909'], | |
| 261 ['Roosevelt, Franklin D', '03/04/1933', 32], ['collected'], | |
| 262 [44, 88, 49, 68], [1, 49, 71], [984, 2016, 'fixed'], | |
| 263 [0, 0, 0, 'pristine', 'daily'] | |
| 264 ]; | |
| 265 | |
| 266 if (!deepEquals(expected, result)) { | |
| 267 throw new Error("FAILURE"); | |
| 268 } | |
| 269 return true; | |
| 270 } | |
| OLD | NEW |