| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 var MapBenchmark = new BenchmarkSuite('WeakMap', [1000], [ | 6 var MapBenchmark = new BenchmarkSuite('WeakMap', [1000], [ |
| 7 new Benchmark('Set', false, false, 0, WeakMapSet), | 7 new Benchmark('Set', false, false, 0, WeakMapSet, WeakMapSetupBase, |
| 8 WeakMapTearDown), |
| 8 new Benchmark('Has', false, false, 0, WeakMapHas, WeakMapSetup, | 9 new Benchmark('Has', false, false, 0, WeakMapHas, WeakMapSetup, |
| 9 WeakMapTearDown), | 10 WeakMapTearDown), |
| 10 new Benchmark('Get', false, false, 0, WeakMapGet, WeakMapSetup, | 11 new Benchmark('Get', false, false, 0, WeakMapGet, WeakMapSetup, |
| 11 WeakMapTearDown), | 12 WeakMapTearDown), |
| 12 new Benchmark('Delete', false, false, 0, WeakMapDelete, WeakMapSetup, | 13 new Benchmark('Delete', false, false, 0, WeakMapDelete, WeakMapSetup, |
| 13 WeakMapTearDown), | 14 WeakMapTearDown), |
| 14 ]); | 15 ]); |
| 15 | 16 |
| 16 | 17 |
| 17 var wm; | 18 var wm; |
| 18 var N = 10; | |
| 19 var keys = []; | |
| 20 | 19 |
| 21 | 20 |
| 22 for (var i = 0; i < N * 2; i++) { | 21 function WeakMapSetupBase() { |
| 23 keys[i] = {}; | 22 SetupObjectKeys(); |
| 23 wm = new WeakMap; |
| 24 } | 24 } |
| 25 | 25 |
| 26 | 26 |
| 27 function WeakMapSetup() { | 27 function WeakMapSetup() { |
| 28 wm = new WeakMap; | 28 WeakMapSetupBase(); |
| 29 for (var i = 0; i < N; i++) { | 29 WeakMapSet(); |
| 30 wm.set(keys[i], i); | |
| 31 } | |
| 32 } | 30 } |
| 33 | 31 |
| 34 | 32 |
| 35 function WeakMapTearDown() { | 33 function WeakMapTearDown() { |
| 36 wm = null; | 34 wm = null; |
| 37 } | 35 } |
| 38 | 36 |
| 39 | 37 |
| 40 function WeakMapSet() { | 38 function WeakMapSet() { |
| 41 WeakMapSetup(); | 39 for (var i = 0; i < N; i++) { |
| 42 WeakMapTearDown(); | 40 wm.set(keys[i], i); |
| 41 } |
| 43 } | 42 } |
| 44 | 43 |
| 45 | 44 |
| 46 function WeakMapHas() { | 45 function WeakMapHas() { |
| 47 for (var i = 0; i < N; i++) { | 46 for (var i = 0; i < N; i++) { |
| 48 if (!wm.has(keys[i])) { | 47 if (!wm.has(keys[i])) { |
| 49 throw new Error(); | 48 throw new Error(); |
| 50 } | 49 } |
| 51 } | 50 } |
| 52 for (var i = N; i < 2 * N; i++) { | 51 for (var i = N; i < 2 * N; i++) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 71 } | 70 } |
| 72 | 71 |
| 73 | 72 |
| 74 function WeakMapDelete() { | 73 function WeakMapDelete() { |
| 75 // This is run more than once per setup so we will end up deleting items | 74 // This is run more than once per setup so we will end up deleting items |
| 76 // more than once. Therefore, we do not the return value of delete. | 75 // more than once. Therefore, we do not the return value of delete. |
| 77 for (var i = 0; i < N; i++) { | 76 for (var i = 0; i < N; i++) { |
| 78 wm.delete(keys[i]); | 77 wm.delete(keys[i]); |
| 79 } | 78 } |
| 80 } | 79 } |
| OLD | NEW |