OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 |
| 6 var SetBenchmark = new BenchmarkSuite('WeakSet', [1000], [ |
| 7 new Benchmark('Add', false, false, 0, WeakSetAdd), |
| 8 new Benchmark('Has', false, false, 0, WeakSetHas, WeakSetSetup, |
| 9 WeakSetTearDown), |
| 10 new Benchmark('Delete', false, false, 0, WeakSetDelete, WeakSetSetup, |
| 11 WeakSetTearDown), |
| 12 ]); |
| 13 |
| 14 |
| 15 var ws; |
| 16 var N = 10; |
| 17 var keys = []; |
| 18 |
| 19 |
| 20 for (var i = 0; i < N * 2; i++) { |
| 21 keys[i] = {}; |
| 22 } |
| 23 |
| 24 |
| 25 function WeakSetSetup() { |
| 26 ws = new WeakSet; |
| 27 for (var i = 0; i < N; i++) { |
| 28 ws.add(keys[i]); |
| 29 } |
| 30 } |
| 31 |
| 32 |
| 33 function WeakSetTearDown() { |
| 34 ws = null; |
| 35 } |
| 36 |
| 37 |
| 38 function WeakSetAdd() { |
| 39 WeakSetSetup(); |
| 40 WeakSetTearDown(); |
| 41 } |
| 42 |
| 43 |
| 44 function WeakSetHas() { |
| 45 for (var i = 0; i < N; i++) { |
| 46 if (!ws.has(keys[i])) { |
| 47 throw new Error(); |
| 48 } |
| 49 } |
| 50 for (var i = N; i < 2 * N; i++) { |
| 51 if (ws.has(keys[i])) { |
| 52 throw new Error(); |
| 53 } |
| 54 } |
| 55 } |
| 56 |
| 57 |
| 58 function WeakSetDelete() { |
| 59 // This is run more than once per setup so we will end up deleting items |
| 60 // more than once. Therefore, we do not the return value of delete. |
| 61 for (var i = 0; i < N; i++) { |
| 62 ws.delete(keys[i]); |
| 63 } |
| 64 } |
OLD | NEW |