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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: test/js-perf-test/Object/entries.js
diff --git a/test/js-perf-test/Object/entries.js b/test/js-perf-test/Object/entries.js
new file mode 100644
index 0000000000000000000000000000000000000000..0f7ce5dbd87c299b43f36a27a0093c9219964902
--- /dev/null
+++ b/test/js-perf-test/Object/entries.js
@@ -0,0 +1,337 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+new BenchmarkSuite('Entries', [1000], [
+ new Benchmark('Basic', false, false, 0, Basic, BasicSetup, BasicTearDown),
+ new Benchmark('BasicMegamorphic', false, false, 0, BasicMegamorphic,
+ BasicMegamorphicSetup, BasicMegamorphicTearDown)
+]);
+
+var object;
+var symbol1;
+var symbol2;
+var result;
+
+function Basic() {
+ result = Object.entries(object);
+}
+
+
+function BasicSetup() {
+ result = undefined;
+ symbol1 = Symbol('test');
+ object = { a: 10 };
+ object[26.0] = 'third';
+ object.b = 72;
+ object[symbol1] = 'TEST';
+ Object.defineProperty(object, 'not-enumerable', {
+ enumerable: false, value: 'nope', writable: true, configurable: true });
+}
+
+
+function BasicTearDown() {
+ result = result.map(entry => `[${[String(entry[0]), String(entry[1])]}]`);
+ return result.length === 3 &&
+ result.join(', ') === '[a, 10], [26.0, third], [b, 72]';
+}
+
+// ----------------------------------------------------------------------------
+
+function BasicMegamorphic() {
+ result = [
+ Object.entries(object[0]), Object.entries(object[1]), Object.entries(object[2]),
+ Object.entries(object[3]), Object.entries(object[4]), Object.entries(object[5]),
+ Object.entries(object[6]), Object.entries(object[7]), Object.entries(object[8]),
+ Object.entries(object[9]), Object.entries(object[10]), Object.entries(object[11]),
+ Object.entries(object[12]), Object.entries(object[13]), Object.entries(object[14]),
+ Object.entries(object[15]), Object.entries(object[16]), Object.entries(object[17]),
+ Object.entries(object[18]), Object.entries(object[19]), Object.entries(object[20]),
+ Object.entries(object[21]), Object.entries(object[22]), Object.entries(object[23]),
+ Object.entries(object[24]),
+ Object.entries(object[0]), Object.entries(object[1]), Object.entries(object[2]),
+ Object.entries(object[3]), Object.entries(object[4]), Object.entries(object[5]),
+ Object.entries(object[6]), Object.entries(object[7]), Object.entries(object[8]),
+ Object.entries(object[9]), Object.entries(object[10]), Object.entries(object[11]),
+ Object.entries(object[12]), Object.entries(object[13]), Object.entries(object[14]),
+ Object.entries(object[15]), Object.entries(object[16]), Object.entries(object[17]),
+ Object.entries(object[18]), Object.entries(object[19]), Object.entries(object[20]),
+ Object.entries(object[21]), Object.entries(object[22]), Object.entries(object[23]),
+ Object.entries(object[24]),
+ Object.entries(object[0]), Object.entries(object[1]), Object.entries(object[2]),
+ Object.entries(object[3]), Object.entries(object[4]), Object.entries(object[5]),
+ Object.entries(object[6]), Object.entries(object[7]), Object.entries(object[8]),
+ Object.entries(object[9]), Object.entries(object[10]), Object.entries(object[11]),
+ Object.entries(object[12]), Object.entries(object[13]), Object.entries(object[14]),
+ Object.entries(object[15]), Object.entries(object[16]), Object.entries(object[17]),
+ Object.entries(object[18]), Object.entries(object[19]), Object.entries(object[20]),
+ Object.entries(object[21]), Object.entries(object[22]), Object.entries(object[23]),
+ Object.entries(object[24]),
+ Object.entries(object[0]), Object.entries(object[1]), Object.entries(object[2]),
+ Object.entries(object[3]), Object.entries(object[4]), Object.entries(object[5]),
+ Object.entries(object[6]), Object.entries(object[7]), Object.entries(object[8]),
+ Object.entries(object[9]), Object.entries(object[10]), Object.entries(object[11]),
+ Object.entries(object[12]), Object.entries(object[13]), Object.entries(object[14]),
+ Object.entries(object[15]), Object.entries(object[16]), Object.entries(object[17]),
+ Object.entries(object[18]), Object.entries(object[19]), Object.entries(object[20]),
+ Object.entries(object[21]), Object.entries(object[22]), Object.entries(object[23]),
+ Object.entries(object[24]),
+ ];
+}
+
+
+function BasicMegamorphicSetup() {
+ symbol1 = Symbol('megamorphicTest');
+ symbol2 = Symbol('megamorphicTest2');
+ object = [
+ { a: 1, [symbol1]: 'ignored' },
+ { q: 'q', [symbol1]: 'ignored', zz: '2' },
+ { precedence: 13, operator: '*', lhs: 4.7, rhs: 5.9 },
+ { name: 'Wiggins', occupation: 'woofer', age: 4, breed: 'papillon' },
+ { author: 'Ted Chiang', title: 'The Lifecycle Of Software Objects',
+ isbn: '978-1-59606-317-4' },
+ { lemon_zest: true, [symbol1]: 'ignored', },
+ { elite_status: 'zerpaderp', airline: 'Bambasherp Airways' },
+ { card_no: 'xxxx-xxxx-xxxx-xxxx', exp_date: 'mm/dd',
+ card_holder: 'Zapp Brannigan', authorized_date: '01/02/3066' },
+ { [symbol1]: 'ignored', a: 49 },
+ { a: 64, [symbol1]: 'ignored', b: 45 },
+ { a: 64, [symbol1]: 'ignored', c: 72 },
+ { operator: '>>>', lhs: 0x8000, rhs: 2, precedence: 11 },
+ { [symbol1]: 'ignored', lemon_zest: false, basil: true },
+ Object.defineProperty({ a: 64, [symbol1]: 'ignored', b: 45 }, '_hidden', {
+ get() { return 'ignored!' },
+ set() { throw new Error('NO!'); },
+ enumerable: false, configurable: false
+ }),
+ Object.defineProperty({ exp_date: 'mm/dd', card_no: 'xxx-xxx-xxx-xxx',
+ card_holder: 'Zapp Brannigan' }, 'declined', {
+ value: '01/02/3066',
+ enumerable: true,
+ configurable: false,
+ writable: false
+ }),
+ { item: 'potato', qty: '6.7kg', date: '02/13/1947' },
+ { date: '02/27/1948', item: 'scallop', qty: '3.4kg' },
+ { qty: '448g', item: 'peppercorn', date: '03/17/1948', delivery: true },
+ { number: 26, name: 'Taft, William Howard', sworn: '03/04/1909' },
+ { name: 'Roosevelt, Franklin D', sworn: '03/04/1933', number: 32 },
+ { [symbol2]: 'symbol2', [symbol1]: 'symbol1', token: 'collected' },
+ { 0: 44, 1: 88, a: 49, b: 68 },
+ { 44: 1, a: 49, c: 71 },
+ { count: 984, year: 2016, bugs: 'fixed' },
+ { cavities: 0, fillers: 0, cracks: 0, color: 'pristine', flosses: 'daily' }
+ ];
+}
+
+
+function BasicMegamorphicTearDown() {
+ // TODO(caitp): move these result verifier utilities (from mjsunit.js) to
+ // base.js? Or just load mjsunit.js?
+ var ObjectPrototypeToString = Object.prototype.toString;
+ var NumberPrototypeValueOf = Number.prototype.valueOf;
+ var BooleanPrototypeValueOf = Boolean.prototype.valueOf;
+ var StringPrototypeValueOf = String.prototype.valueOf;
+ var DatePrototypeValueOf = Date.prototype.valueOf;
+ var RegExpPrototypeToString = RegExp.prototype.toString;
+ var ArrayPrototypeMap = Array.prototype.map;
+ var ArrayPrototypeJoin = Array.prototype.join;
+
+ function classOf(object) {
+ // Argument must not be null or undefined.
+ var string = ObjectPrototypeToString.call(object);
+ // String has format [object <ClassName>].
+ return string.substring(8, string.length - 1);
+ }
+
+
+ function ValueOf(value) {
+ switch (classOf(value)) {
+ case "Number":
+ return NumberPrototypeValueOf.call(value);
+ case "String":
+ return StringPrototypeValueOf.call(value);
+ case "Boolean":
+ return BooleanPrototypeValueOf.call(value);
+ case "Date":
+ return DatePrototypeValueOf.call(value);
+ default:
+ return value;
+ }
+ }
+
+ function deepObjectEquals(a, b) {
+ var aProps = Object.keys(a);
+ aProps.sort();
+ var bProps = Object.keys(b);
+ bProps.sort();
+ if (!deepEquals(aProps, bProps)) {
+ return false;
+ }
+ for (var i = 0; i < aProps.length; i++) {
+ if (!deepEquals(a[aProps[i]], b[aProps[i]])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ function deepEquals(a, b) {
+ if (a === b) {
+ // Check for -0.
+ if (a === 0) return (1 / a) === (1 / b);
+ return true;
+ }
+ if (typeof a !== typeof b) return false;
+ if (typeof a === "number") return isNaN(a) && isNaN(b);
+ if (typeof a !== "object" && typeof a !== "function") return false;
+ // Neither a nor b is primitive.
+ var objectClass = classOf(a);
+ if (objectClass !== classOf(b)) return false;
+ if (objectClass === "RegExp") {
+ // For RegExp, just compare pattern and flags using its toString.
+ return RegExpPrototypeToString.call(a) ===
+ RegExpPrototypeToString.call(b);
+ }
+ // Functions are only identical to themselves.
+ if (objectClass === "Function") return false;
+ if (objectClass === "Array") {
+ var elementCount = 0;
+ if (a.length !== b.length) {
+ return false;
+ }
+ for (var i = 0; i < a.length; i++) {
+ if (!deepEquals(a[i], b[i])) return false;
+ }
+ return true;
+ }
+ if (objectClass === "String" || objectClass === "Number" ||
+ objectClass === "Boolean" || objectClass === "Date") {
+ if (ValueOf(a) !== ValueOf(b)) return false;
+ }
+ return deepObjectEquals(a, b);
+ }
+
+ if (!deepEquals([
+ [['a', 1]], [['q','q'], ['zz', '2']],
+ [['precedence', 13], ['operator', '*'], ['lhs', 4.7], ['rhs', 5.9]],
+ [['name', 'Wiggins'], ['occupation', 'woofer'], ['age', 4],
+ ['breed', 'papillon']],
+ [['author', 'Ted Chiang'], ['title', 'The Lifecycle Of Software Objects'],
+ ['isbn', '978-1-59606-317-4']],
+ [['lemon_zest', true]],
+ [['elite_status', 'zerpaderp'], ['airline', 'Bambasherp Airways']],
+ [['card_no', 'xxxx-xxxx-xxxx-xxxx'], ['exp_date', 'mm/dd'],
+ ['card_holder', 'Zapp Brannigan'], ['authorized_date', '01/02/3066']],
+ [['a', 49]], [['a', 64], ['b', 45]], [['a', 64], ['c', 72]],
+ [['operator', '>>>'], ['lhs', 0x8000], ['rhs', 2], ['precedence', 11]],
+ [['lemon_zest', false], ['basil', true]],
+ [['a', 64], ['b', 45]],
+ [['exp_date', 'mm/dd'], ['card_no', 'xxx-xxx-xxx-xxx'],
+ ['card_holder', 'Zapp Brannigan'], ['declined', '01/02/3066']],
+ [['item', 'potato'], ['qty', '6.7kg'], ['date', '02/13/1947']],
+ [['date', '02/27/1948'], ['item', 'scallop'], ['qty', '3.4kg']],
+ [['qty', '448g'], ['item', 'peppercorn'], ['date', '03/17/1948'],
+ ['delivery', true]],
+ [['number', 26], ['name', 'Taft, William Howard'], ['sworn', '03/04/1909']],
+ [['name', 'Roosevelt, Franklin D'], ['sworn', '03/04/1933'],
+ ['number', 32]],
+ [['token', 'collected']],
+ [['0', 44], ['1', 88], ['a', 49], ['b', 68]],
+ [['44', 1], ['a', 49], ['c', 71]],
+ [['count', 984], ['year', 2016], ['bugs', 'fixed']],
+ [['cavities', 0], ['fillers', 0], ['cracks', 0], ['color', 'pristine'],
+ ['flosses', 'daily']],
+ [['a', 1]], [['q','q'], ['zz', '2']],
+ [['precedence', 13], ['operator', '*'], ['lhs', 4.7], ['rhs', 5.9]],
+ [['name', 'Wiggins'], ['occupation', 'woofer'], ['age', 4],
+ ['breed', 'papillon']],
+ [['author', 'Ted Chiang'], ['title', 'The Lifecycle Of Software Objects'],
+ ['isbn', '978-1-59606-317-4']],
+ [['lemon_zest', true]],
+ [['elite_status', 'zerpaderp'], ['airline', 'Bambasherp Airways']],
+ [['card_no', 'xxxx-xxxx-xxxx-xxxx'], ['exp_date', 'mm/dd'],
+ ['card_holder', 'Zapp Brannigan'], ['authorized_date', '01/02/3066']],
+ [['a', 49]], [['a', 64], ['b', 45]], [['a', 64], ['c', 72]],
+ [['operator', '>>>'], ['lhs', 0x8000], ['rhs', 2], ['precedence', 11]],
+ [['lemon_zest', false], ['basil', true]],
+ [['a', 64], ['b', 45]],
+ [['exp_date', 'mm/dd'], ['card_no', 'xxx-xxx-xxx-xxx'],
+ ['card_holder', 'Zapp Brannigan'], ['declined', '01/02/3066']],
+ [['item', 'potato'], ['qty', '6.7kg'], ['date', '02/13/1947']],
+ [['date', '02/27/1948'], ['item', 'scallop'], ['qty', '3.4kg']],
+ [['qty', '448g'], ['item', 'peppercorn'], ['date', '03/17/1948'],
+ ['delivery', true]],
+ [['number', 26], ['name', 'Taft, William Howard'], ['sworn', '03/04/1909']],
+ [['name', 'Roosevelt, Franklin D'], ['sworn', '03/04/1933'],
+ ['number', 32]],
+ [['token', 'collected']],
+ [['0', 44], ['1', 88], ['a', 49], ['b', 68]],
+ [['44', 1], ['a', 49], ['c', 71]],
+ [['count', 984], ['year', 2016], ['bugs', 'fixed']],
+ [['cavities', 0], ['fillers', 0], ['cracks', 0], ['color', 'pristine'],
+ ['flosses', 'daily']],
+ [['a', 1]], [['q','q'], ['zz', '2']],
+ [['precedence', 13], ['operator', '*'], ['lhs', 4.7], ['rhs', 5.9]],
+ [['name', 'Wiggins'], ['occupation', 'woofer'], ['age', 4],
+ ['breed', 'papillon']],
+ [['author', 'Ted Chiang'], ['title', 'The Lifecycle Of Software Objects'],
+ ['isbn', '978-1-59606-317-4']],
+ [['lemon_zest', true]],
+ [['elite_status', 'zerpaderp'], ['airline', 'Bambasherp Airways']],
+ [['card_no', 'xxxx-xxxx-xxxx-xxxx'], ['exp_date', 'mm/dd'],
+ ['card_holder', 'Zapp Brannigan'], ['authorized_date', '01/02/3066']],
+ [['a', 49]], [['a', 64], ['b', 45]], [['a', 64], ['c', 72]],
+ [['operator', '>>>'], ['lhs', 0x8000], ['rhs', 2], ['precedence', 11]],
+ [['lemon_zest', false], ['basil', true]],
+ [['a', 64], ['b', 45]],
+ [['exp_date', 'mm/dd'], ['card_no', 'xxx-xxx-xxx-xxx'],
+ ['card_holder', 'Zapp Brannigan'], ['declined', '01/02/3066']],
+ [['item', 'potato'], ['qty', '6.7kg'], ['date', '02/13/1947']],
+ [['date', '02/27/1948'], ['item', 'scallop'], ['qty', '3.4kg']],
+ [['qty', '448g'], ['item', 'peppercorn'], ['date', '03/17/1948'],
+ ['delivery', true]],
+ [['number', 26], ['name', 'Taft, William Howard'], ['sworn', '03/04/1909']],
+ [['name', 'Roosevelt, Franklin D'], ['sworn', '03/04/1933'],
+ ['number', 32]],
+ [['token', 'collected']],
+ [['0', 44], ['1', 88], ['a', 49], ['b', 68]],
+ [['44', 1], ['a', 49], ['c', 71]],
+ [['count', 984], ['year', 2016], ['bugs', 'fixed']],
+ [['cavities', 0], ['fillers', 0], ['cracks', 0], ['color', 'pristine'],
+ ['flosses', 'daily']],
+ [['a', 1]], [['q','q'], ['zz', '2']],
+ [['precedence', 13], ['operator', '*'], ['lhs', 4.7], ['rhs', 5.9]],
+ [['name', 'Wiggins'], ['occupation', 'woofer'], ['age', 4],
+ ['breed', 'papillon']],
+ [['author', 'Ted Chiang'], ['title', 'The Lifecycle Of Software Objects'],
+ ['isbn', '978-1-59606-317-4']],
+ [['lemon_zest', true]],
+ [['elite_status', 'zerpaderp'], ['airline', 'Bambasherp Airways']],
+ [['card_no', 'xxxx-xxxx-xxxx-xxxx'], ['exp_date', 'mm/dd'],
+ ['card_holder', 'Zapp Brannigan'], ['authorized_date', '01/02/3066']],
+ [['a', 49]], [['a', 64], ['b', 45]], [['a', 64], ['c', 72]],
+ [['operator', '>>>'], ['lhs', 0x8000], ['rhs', 2], ['precedence', 11]],
+ [['lemon_zest', false], ['basil', true]],
+ [['a', 64], ['b', 45]],
+ [['exp_date', 'mm/dd'], ['card_no', 'xxx-xxx-xxx-xxx'],
+ ['card_holder', 'Zapp Brannigan'], ['declined', '01/02/3066']],
+ [['item', 'potato'], ['qty', '6.7kg'], ['date', '02/13/1947']],
+ [['date', '02/27/1948'], ['item', 'scallop'], ['qty', '3.4kg']],
+ [['qty', '448g'], ['item', 'peppercorn'], ['date', '03/17/1948'],
+ ['delivery', true]],
+ [['number', 26], ['name', 'Taft, William Howard'], ['sworn', '03/04/1909']],
+ [['name', 'Roosevelt, Franklin D'], ['sworn', '03/04/1933'],
+ ['number', 32]],
+ [['token', 'collected']],
+ [['0', 44], ['1', 88], ['a', 49], ['b', 68]],
+ [['44', 1], ['a', 49], ['c', 71]],
+ [['count', 984], ['year', 2016], ['bugs', 'fixed']],
+ [['cavities', 0], ['fillers', 0], ['cracks', 0], ['color', 'pristine'],
+ ['flosses', 'daily']],
+ ], result)) {
+ throw new Error("FAILURE");
+ }
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698