Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: test/js-perf-test/Object/entries.js

Issue 1746383003: [js-perf-test] add microbenchmarks for Object.values(), Object.entries() (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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('Entries', [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.entries(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 result = result.map(entry => `[${[String(entry[0]), String(entry[1])]}]`);
35 return result.length === 3 &&
36 result.join(', ') === '[a, 10], [26.0, third], [b, 72]';
37 }
38
39 // ----------------------------------------------------------------------------
40
41 function BasicMegamorphic() {
42 result = [
43 Object.entries(object[0]), Object.entries(object[1]), Object.entries(object[ 2]),
44 Object.entries(object[3]), Object.entries(object[4]), Object.entries(object[ 5]),
45 Object.entries(object[6]), Object.entries(object[7]), Object.entries(object[ 8]),
46 Object.entries(object[9]), Object.entries(object[10]), Object.entries(object [11]),
47 Object.entries(object[12]), Object.entries(object[13]), Object.entries(objec t[14]),
48 Object.entries(object[15]), Object.entries(object[16]), Object.entries(objec t[17]),
49 Object.entries(object[18]), Object.entries(object[19]), Object.entries(objec t[20]),
50 Object.entries(object[21]), Object.entries(object[22]), Object.entries(objec t[23]),
51 Object.entries(object[24]),
52 Object.entries(object[0]), Object.entries(object[1]), Object.entries(object[ 2]),
53 Object.entries(object[3]), Object.entries(object[4]), Object.entries(object[ 5]),
54 Object.entries(object[6]), Object.entries(object[7]), Object.entries(object[ 8]),
55 Object.entries(object[9]), Object.entries(object[10]), Object.entries(object [11]),
56 Object.entries(object[12]), Object.entries(object[13]), Object.entries(objec t[14]),
57 Object.entries(object[15]), Object.entries(object[16]), Object.entries(objec t[17]),
58 Object.entries(object[18]), Object.entries(object[19]), Object.entries(objec t[20]),
59 Object.entries(object[21]), Object.entries(object[22]), Object.entries(objec t[23]),
60 Object.entries(object[24]),
61 Object.entries(object[0]), Object.entries(object[1]), Object.entries(object[ 2]),
62 Object.entries(object[3]), Object.entries(object[4]), Object.entries(object[ 5]),
63 Object.entries(object[6]), Object.entries(object[7]), Object.entries(object[ 8]),
64 Object.entries(object[9]), Object.entries(object[10]), Object.entries(object [11]),
65 Object.entries(object[12]), Object.entries(object[13]), Object.entries(objec t[14]),
66 Object.entries(object[15]), Object.entries(object[16]), Object.entries(objec t[17]),
67 Object.entries(object[18]), Object.entries(object[19]), Object.entries(objec t[20]),
68 Object.entries(object[21]), Object.entries(object[22]), Object.entries(objec t[23]),
69 Object.entries(object[24]),
70 Object.entries(object[0]), Object.entries(object[1]), Object.entries(object[ 2]),
71 Object.entries(object[3]), Object.entries(object[4]), Object.entries(object[ 5]),
72 Object.entries(object[6]), Object.entries(object[7]), Object.entries(object[ 8]),
73 Object.entries(object[9]), Object.entries(object[10]), Object.entries(object [11]),
74 Object.entries(object[12]), Object.entries(object[13]), Object.entries(objec t[14]),
75 Object.entries(object[15]), Object.entries(object[16]), Object.entries(objec t[17]),
76 Object.entries(object[18]), Object.entries(object[19]), Object.entries(objec t[20]),
77 Object.entries(object[21]), Object.entries(object[22]), Object.entries(objec t[23]),
78 Object.entries(object[24]),
79 ];
80 }
81
82
83 function BasicMegamorphicSetup() {
84 symbol1 = Symbol('megamorphicTest');
85 symbol2 = Symbol('megamorphicTest2');
86 object = [
87 { a: 1, [symbol1]: 'ignored' },
88 { q: 'q', [symbol1]: 'ignored', zz: '2' },
89 { precedence: 13, operator: '*', lhs: 4.7, rhs: 5.9 },
90 { name: 'Wiggins', occupation: 'woofer', age: 4, breed: 'papillon' },
91 { author: 'Ted Chiang', title: 'The Lifecycle Of Software Objects',
92 isbn: '978-1-59606-317-4' },
93 { lemon_zest: true, [symbol1]: 'ignored', },
94 { elite_status: 'zerpaderp', airline: 'Bambasherp Airways' },
95 { card_no: 'xxxx-xxxx-xxxx-xxxx', exp_date: 'mm/dd',
96 card_holder: 'Zapp Brannigan', authorized_date: '01/02/3066' },
97 { [symbol1]: 'ignored', a: 49 },
98 { a: 64, [symbol1]: 'ignored', b: 45 },
99 { a: 64, [symbol1]: 'ignored', c: 72 },
100 { operator: '>>>', lhs: 0x8000, rhs: 2, precedence: 11 },
101 { [symbol1]: 'ignored', lemon_zest: false, basil: true },
102 Object.defineProperty({ a: 64, [symbol1]: 'ignored', b: 45 }, '_hidden', {
103 get() { return 'ignored!' },
104 set() { throw new Error('NO!'); },
105 enumerable: false, configurable: false
106 }),
107 Object.defineProperty({ exp_date: 'mm/dd', card_no: 'xxx-xxx-xxx-xxx',
108 card_holder: 'Zapp Brannigan' }, 'declined', {
109 value: '01/02/3066',
110 enumerable: true,
111 configurable: false,
112 writable: false
113 }),
114 { item: 'potato', qty: '6.7kg', date: '02/13/1947' },
115 { date: '02/27/1948', item: 'scallop', qty: '3.4kg' },
116 { qty: '448g', item: 'peppercorn', date: '03/17/1948', delivery: true },
117 { number: 26, name: 'Taft, William Howard', sworn: '03/04/1909' },
118 { name: 'Roosevelt, Franklin D', sworn: '03/04/1933', number: 32 },
119 { [symbol2]: 'symbol2', [symbol1]: 'symbol1', token: 'collected' },
120 { 0: 44, 1: 88, a: 49, b: 68 },
121 { 44: 1, a: 49, c: 71 },
122 { count: 984, year: 2016, bugs: 'fixed' },
123 { cavities: 0, fillers: 0, cracks: 0, color: 'pristine', flosses: 'daily' }
124 ];
125 }
126
127
128 function BasicMegamorphicTearDown() {
129 // TODO(caitp): move these result verifier utilities (from mjsunit.js) to
130 // base.js? Or just load mjsunit.js?
131 var ObjectPrototypeToString = Object.prototype.toString;
132 var NumberPrototypeValueOf = Number.prototype.valueOf;
133 var BooleanPrototypeValueOf = Boolean.prototype.valueOf;
134 var StringPrototypeValueOf = String.prototype.valueOf;
135 var DatePrototypeValueOf = Date.prototype.valueOf;
136 var RegExpPrototypeToString = RegExp.prototype.toString;
137 var ArrayPrototypeMap = Array.prototype.map;
138 var ArrayPrototypeJoin = Array.prototype.join;
139
140 function classOf(object) {
141 // Argument must not be null or undefined.
142 var string = ObjectPrototypeToString.call(object);
143 // String has format [object <ClassName>].
144 return string.substring(8, string.length - 1);
145 }
146
147
148 function ValueOf(value) {
149 switch (classOf(value)) {
150 case "Number":
151 return NumberPrototypeValueOf.call(value);
152 case "String":
153 return StringPrototypeValueOf.call(value);
154 case "Boolean":
155 return BooleanPrototypeValueOf.call(value);
156 case "Date":
157 return DatePrototypeValueOf.call(value);
158 default:
159 return value;
160 }
161 }
162
163 function deepObjectEquals(a, b) {
164 var aProps = Object.keys(a);
165 aProps.sort();
166 var bProps = Object.keys(b);
167 bProps.sort();
168 if (!deepEquals(aProps, bProps)) {
169 return false;
170 }
171 for (var i = 0; i < aProps.length; i++) {
172 if (!deepEquals(a[aProps[i]], b[aProps[i]])) {
173 return false;
174 }
175 }
176 return true;
177 }
178
179
180 function deepEquals(a, b) {
181 if (a === b) {
182 // Check for -0.
183 if (a === 0) return (1 / a) === (1 / b);
184 return true;
185 }
186 if (typeof a !== typeof b) return false;
187 if (typeof a === "number") return isNaN(a) && isNaN(b);
188 if (typeof a !== "object" && typeof a !== "function") return false;
189 // Neither a nor b is primitive.
190 var objectClass = classOf(a);
191 if (objectClass !== classOf(b)) return false;
192 if (objectClass === "RegExp") {
193 // For RegExp, just compare pattern and flags using its toString.
194 return RegExpPrototypeToString.call(a) ===
195 RegExpPrototypeToString.call(b);
196 }
197 // Functions are only identical to themselves.
198 if (objectClass === "Function") return false;
199 if (objectClass === "Array") {
200 var elementCount = 0;
201 if (a.length !== b.length) {
202 return false;
203 }
204 for (var i = 0; i < a.length; i++) {
205 if (!deepEquals(a[i], b[i])) return false;
206 }
207 return true;
208 }
209 if (objectClass === "String" || objectClass === "Number" ||
210 objectClass === "Boolean" || objectClass === "Date") {
211 if (ValueOf(a) !== ValueOf(b)) return false;
212 }
213 return deepObjectEquals(a, b);
214 }
215
216 if (!deepEquals([
217 [['a', 1]], [['q','q'], ['zz', '2']],
218 [['precedence', 13], ['operator', '*'], ['lhs', 4.7], ['rhs', 5.9]],
219 [['name', 'Wiggins'], ['occupation', 'woofer'], ['age', 4],
220 ['breed', 'papillon']],
221 [['author', 'Ted Chiang'], ['title', 'The Lifecycle Of Software Objects'],
222 ['isbn', '978-1-59606-317-4']],
223 [['lemon_zest', true]],
224 [['elite_status', 'zerpaderp'], ['airline', 'Bambasherp Airways']],
225 [['card_no', 'xxxx-xxxx-xxxx-xxxx'], ['exp_date', 'mm/dd'],
226 ['card_holder', 'Zapp Brannigan'], ['authorized_date', '01/02/3066']],
227 [['a', 49]], [['a', 64], ['b', 45]], [['a', 64], ['c', 72]],
228 [['operator', '>>>'], ['lhs', 0x8000], ['rhs', 2], ['precedence', 11]],
229 [['lemon_zest', false], ['basil', true]],
230 [['a', 64], ['b', 45]],
231 [['exp_date', 'mm/dd'], ['card_no', 'xxx-xxx-xxx-xxx'],
232 ['card_holder', 'Zapp Brannigan'], ['declined', '01/02/3066']],
233 [['item', 'potato'], ['qty', '6.7kg'], ['date', '02/13/1947']],
234 [['date', '02/27/1948'], ['item', 'scallop'], ['qty', '3.4kg']],
235 [['qty', '448g'], ['item', 'peppercorn'], ['date', '03/17/1948'],
236 ['delivery', true]],
237 [['number', 26], ['name', 'Taft, William Howard'], ['sworn', '03/04/1909']],
238 [['name', 'Roosevelt, Franklin D'], ['sworn', '03/04/1933'],
239 ['number', 32]],
240 [['token', 'collected']],
241 [['0', 44], ['1', 88], ['a', 49], ['b', 68]],
242 [['44', 1], ['a', 49], ['c', 71]],
243 [['count', 984], ['year', 2016], ['bugs', 'fixed']],
244 [['cavities', 0], ['fillers', 0], ['cracks', 0], ['color', 'pristine'],
245 ['flosses', 'daily']],
246 [['a', 1]], [['q','q'], ['zz', '2']],
247 [['precedence', 13], ['operator', '*'], ['lhs', 4.7], ['rhs', 5.9]],
248 [['name', 'Wiggins'], ['occupation', 'woofer'], ['age', 4],
249 ['breed', 'papillon']],
250 [['author', 'Ted Chiang'], ['title', 'The Lifecycle Of Software Objects'],
251 ['isbn', '978-1-59606-317-4']],
252 [['lemon_zest', true]],
253 [['elite_status', 'zerpaderp'], ['airline', 'Bambasherp Airways']],
254 [['card_no', 'xxxx-xxxx-xxxx-xxxx'], ['exp_date', 'mm/dd'],
255 ['card_holder', 'Zapp Brannigan'], ['authorized_date', '01/02/3066']],
256 [['a', 49]], [['a', 64], ['b', 45]], [['a', 64], ['c', 72]],
257 [['operator', '>>>'], ['lhs', 0x8000], ['rhs', 2], ['precedence', 11]],
258 [['lemon_zest', false], ['basil', true]],
259 [['a', 64], ['b', 45]],
260 [['exp_date', 'mm/dd'], ['card_no', 'xxx-xxx-xxx-xxx'],
261 ['card_holder', 'Zapp Brannigan'], ['declined', '01/02/3066']],
262 [['item', 'potato'], ['qty', '6.7kg'], ['date', '02/13/1947']],
263 [['date', '02/27/1948'], ['item', 'scallop'], ['qty', '3.4kg']],
264 [['qty', '448g'], ['item', 'peppercorn'], ['date', '03/17/1948'],
265 ['delivery', true]],
266 [['number', 26], ['name', 'Taft, William Howard'], ['sworn', '03/04/1909']],
267 [['name', 'Roosevelt, Franklin D'], ['sworn', '03/04/1933'],
268 ['number', 32]],
269 [['token', 'collected']],
270 [['0', 44], ['1', 88], ['a', 49], ['b', 68]],
271 [['44', 1], ['a', 49], ['c', 71]],
272 [['count', 984], ['year', 2016], ['bugs', 'fixed']],
273 [['cavities', 0], ['fillers', 0], ['cracks', 0], ['color', 'pristine'],
274 ['flosses', 'daily']],
275 [['a', 1]], [['q','q'], ['zz', '2']],
276 [['precedence', 13], ['operator', '*'], ['lhs', 4.7], ['rhs', 5.9]],
277 [['name', 'Wiggins'], ['occupation', 'woofer'], ['age', 4],
278 ['breed', 'papillon']],
279 [['author', 'Ted Chiang'], ['title', 'The Lifecycle Of Software Objects'],
280 ['isbn', '978-1-59606-317-4']],
281 [['lemon_zest', true]],
282 [['elite_status', 'zerpaderp'], ['airline', 'Bambasherp Airways']],
283 [['card_no', 'xxxx-xxxx-xxxx-xxxx'], ['exp_date', 'mm/dd'],
284 ['card_holder', 'Zapp Brannigan'], ['authorized_date', '01/02/3066']],
285 [['a', 49]], [['a', 64], ['b', 45]], [['a', 64], ['c', 72]],
286 [['operator', '>>>'], ['lhs', 0x8000], ['rhs', 2], ['precedence', 11]],
287 [['lemon_zest', false], ['basil', true]],
288 [['a', 64], ['b', 45]],
289 [['exp_date', 'mm/dd'], ['card_no', 'xxx-xxx-xxx-xxx'],
290 ['card_holder', 'Zapp Brannigan'], ['declined', '01/02/3066']],
291 [['item', 'potato'], ['qty', '6.7kg'], ['date', '02/13/1947']],
292 [['date', '02/27/1948'], ['item', 'scallop'], ['qty', '3.4kg']],
293 [['qty', '448g'], ['item', 'peppercorn'], ['date', '03/17/1948'],
294 ['delivery', true]],
295 [['number', 26], ['name', 'Taft, William Howard'], ['sworn', '03/04/1909']],
296 [['name', 'Roosevelt, Franklin D'], ['sworn', '03/04/1933'],
297 ['number', 32]],
298 [['token', 'collected']],
299 [['0', 44], ['1', 88], ['a', 49], ['b', 68]],
300 [['44', 1], ['a', 49], ['c', 71]],
301 [['count', 984], ['year', 2016], ['bugs', 'fixed']],
302 [['cavities', 0], ['fillers', 0], ['cracks', 0], ['color', 'pristine'],
303 ['flosses', 'daily']],
304 [['a', 1]], [['q','q'], ['zz', '2']],
305 [['precedence', 13], ['operator', '*'], ['lhs', 4.7], ['rhs', 5.9]],
306 [['name', 'Wiggins'], ['occupation', 'woofer'], ['age', 4],
307 ['breed', 'papillon']],
308 [['author', 'Ted Chiang'], ['title', 'The Lifecycle Of Software Objects'],
309 ['isbn', '978-1-59606-317-4']],
310 [['lemon_zest', true]],
311 [['elite_status', 'zerpaderp'], ['airline', 'Bambasherp Airways']],
312 [['card_no', 'xxxx-xxxx-xxxx-xxxx'], ['exp_date', 'mm/dd'],
313 ['card_holder', 'Zapp Brannigan'], ['authorized_date', '01/02/3066']],
314 [['a', 49]], [['a', 64], ['b', 45]], [['a', 64], ['c', 72]],
315 [['operator', '>>>'], ['lhs', 0x8000], ['rhs', 2], ['precedence', 11]],
316 [['lemon_zest', false], ['basil', true]],
317 [['a', 64], ['b', 45]],
318 [['exp_date', 'mm/dd'], ['card_no', 'xxx-xxx-xxx-xxx'],
319 ['card_holder', 'Zapp Brannigan'], ['declined', '01/02/3066']],
320 [['item', 'potato'], ['qty', '6.7kg'], ['date', '02/13/1947']],
321 [['date', '02/27/1948'], ['item', 'scallop'], ['qty', '3.4kg']],
322 [['qty', '448g'], ['item', 'peppercorn'], ['date', '03/17/1948'],
323 ['delivery', true]],
324 [['number', 26], ['name', 'Taft, William Howard'], ['sworn', '03/04/1909']],
325 [['name', 'Roosevelt, Franklin D'], ['sworn', '03/04/1933'],
326 ['number', 32]],
327 [['token', 'collected']],
328 [['0', 44], ['1', 88], ['a', 49], ['b', 68]],
329 [['44', 1], ['a', 49], ['c', 71]],
330 [['count', 984], ['year', 2016], ['bugs', 'fixed']],
331 [['cavities', 0], ['fillers', 0], ['cracks', 0], ['color', 'pristine'],
332 ['flosses', 'daily']],
333 ], result)) {
334 throw new Error("FAILURE");
335 }
336 return true;
337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698