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