Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 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('Values', [1000], [ |
| 6 | new Benchmark('Basic', false, false, 0, Basic, BasicSetup, BasicTearDown), |
| 7 | ]); |
| 8 | |
| 9 | var object; |
| 10 | var expected; |
| 11 | var result; |
| 12 | var symbol1; |
| 13 | |
| 14 | function Basic() { |
| 15 | result = Object.values(object); |
| 16 | } |
| 17 | |
| 18 | |
| 19 | function 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 | |
| 31 | function BasicTearDown() { |
| 32 | return result.length === 3 && result[0] === 10 && result[1] === 'third' && |
| 33 | result[2] === 72; |
| 34 | } |
| 35 | |
| 36 | // ---------------------------------------------------------------------------- |
| 37 | |
| 38 | new BenchmarkSuite('ValuesMegamorphic', [1000], [ |
| 39 | new Benchmark('BasicMegamorphic', false, false, 0, BasicMegamorphic, |
| 40 | BasicMegamorphicSetup, BasicMegamorphicTearDown) |
| 41 | ]); |
| 42 | |
| 43 | |
| 44 | function BasicMegamorphic() { |
| 45 | for (var i = 0; i < object.length; ++i) { |
| 46 | result[i] = Object.values(object[i]); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | |
| 51 | function 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] = 'property-'+i+'-'+j; |
| 62 | } |
| 63 | object[i] = obj; |
| 64 | expected[i] = exp; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | |
| 69 | function BasicMegamorphicTearDown() { |
| 70 | if (JSON.stringify(expected) !== JSON.stringify(result)) { |
| 71 | throw new Error("FAILURE"); |
| 72 | } |
| 73 | object = result = expected = undefined; |
| 74 | return true; |
| 75 | } |