• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5new BenchmarkSuite('Entries', [1000], [
6  new Benchmark('Basic', false, false, 0, Basic, BasicSetup, BasicTearDown)
7]);
8
9var object;
10var expected;
11var result;
12var symbol1;
13
14function Basic() {
15  result = Object.entries(object);
16}
17
18
19function BasicSetup() {
20  result = undefined;
21  symbol1 = Symbol('test');
22  object = { a: 10 };
23  object[26.0] = 'third';
24  object.b = 72;
25  object[symbol1] = 'TEST';
26  Object.defineProperty(object, 'not-enumerable', {
27      enumerable: false, value: 'nope', writable: true, configurable: true });
28}
29
30
31function BasicTearDown() {
32  result = result.map(entry => `[${[String(entry[0]), String(entry[1])]}]`);
33  return result.length === 3 &&
34         result.join(', ') === '[a, 10], [26.0, third], [b, 72]';
35}
36
37// ----------------------------------------------------------------------------
38
39new BenchmarkSuite('EntriesMegamorphic', [1000], [
40  new Benchmark('BasicMegamorphic', false, false, 0, BasicMegamorphic,
41                BasicMegamorphicSetup, BasicMegamorphicTearDown)
42]);
43
44function BasicMegamorphic() {
45  for (var i = 0; i < object.length; ++i) {
46    result[i] = Object.entries(object[i]);
47  }
48}
49
50
51function BasicMegamorphicSetup() {
52  // Create 1k objects with different maps.
53  object = [];
54  expected = [];
55  result = [];
56  for (var i=0; i<1000; i++) {
57    var obj = {};
58    var exp = [];
59    for (var j=0; j<10; j++) {
60      obj['key-'+i+'-'+j] = 'property-'+i+'-'+j;
61      exp[j] = ['key-'+i+'-'+j, 'property-'+i+'-'+j];
62    }
63    object[i] = obj;
64    expected[i] = exp;
65  }
66}
67
68
69function BasicMegamorphicTearDown() {
70  if (JSON.stringify(expected) !== JSON.stringify(result)) {
71    throw new Error("FAILURE");
72  }
73  object = result = expected = undefined;
74  return true;
75}
76