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 // ---------------------------------------------------------------------------- |
| 6 |
| 7 function shallowClone(object) { |
| 8 return Object.create(object.__proto__, |
| 9 Object.getOwnPropertyDescriptors(object)); |
| 10 } |
| 11 |
| 12 function makeSlowCopy(object) { |
| 13 object = shallowClone(object); |
| 14 object.__foo__ = 1; |
| 15 delete object.__foo__; |
| 16 return object; |
| 17 } |
| 18 |
| 19 function 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 |
| 27 var properties_5 = { a:1, b:2, c:3, d:4, e:5 }; |
| 28 var 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 |
| 36 var TEST_PROTOTYPES = { |
| 37 null: null, |
| 38 empty: {}, |
| 39 'Object.prototype': Object.prototype, |
| 40 'Array.prototype': Array.prototype |
| 41 }; |
| 42 |
| 43 // ---------------------------------------------------------------------------- |
| 44 |
| 45 var testFunction = () => { |
| 46 return Object.create(prototype, properties); |
| 47 } |
| 48 |
| 49 function 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 |
| 57 var benchmarks = [] |
| 58 |
| 59 for (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 |
| 70 new BenchmarkSuite('Create', [1000], benchmarks); |
OLD | NEW |