blob: 49ebe5c1bf757189cfd1a2dd012fcac1109b4252 [file] [log] [blame]
Andrew Topef837fa2017-10-04 22:44:25 -07001// 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// ----------------------------------------------------------------------------
6
7function shallowClone(object) {
8 return Object.create(object.__proto__,
9 Object.getOwnPropertyDescriptors(object));
10}
11
12function makeSlowCopy(object) {
13 object = shallowClone(object);
14 object.__foo__ = 1;
15 delete object.__foo__;
16 return object;
17}
18
19function convertToPropertyDescriptors(dict) {
20 for (var key in dict) {
21 var propertiesObject = dict[key];
22 dict[key] = Object.getOwnPropertyDescriptors(propertiesObject);
23 }
24 return dict;
25}
26
27var properties_5 = { a:1, b:2, c:3, d:4, e:5 };
28var TEST_PROPERTIES = convertToPropertyDescriptors({
29 empty: {},
30 array_5: [1, 2, 3, 4, 5],
31 properties_5: properties_5,
32 properties_10: { a:1, b:2, c:3, d:4, e:5, f:6, g:7, h:8, i:9, j:10 },
33 properties_dict: makeSlowCopy(properties_5)
34});
35
36var TEST_PROTOTYPES = {
37 null: null,
38 empty: {},
39 'Object.prototype': Object.prototype,
40 'Array.prototype': Array.prototype
41};
42
43// ----------------------------------------------------------------------------
44
45var testFunction = () => {
46 return Object.create(prototype, properties);
47}
48
49function createTestFunction(prototype, properties) {
50 // Force a new function for each test-object to avoid side-effects due to ICs.
51 var random_comment = "\n// random comment" + Math.random() + "\n";
52 return eval(random_comment + testFunction.toString());
53}
54
55// ----------------------------------------------------------------------------
56
57var benchmarks = []
58
59for (var proto_name in TEST_PROTOTYPES) {
60 var prototype = TEST_PROTOTYPES[proto_name];
61 for (var prop_name in TEST_PROPERTIES) {
62 var properties = TEST_PROPERTIES[prop_name];
63 var name = 'Create proto:' + proto_name + " properties:" + prop_name;
64 benchmarks.push(
65 new Benchmark(name, false, false, 0,
66 createTestFunction(prototype, properties)));
67 }
68}
69
70new BenchmarkSuite('Create', [1000], benchmarks);