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 6var SetSmiBenchmark = new BenchmarkSuite('Set-Smi', [1000], [ 7 new Benchmark('Set', false, false, 0, SetAddSmi, SetSetupSmiBase, SetTearDown), 8 new Benchmark('Has', false, false, 0, SetHasSmi, SetSetupSmi, SetTearDown), 9 new Benchmark('Delete', false, false, 0, SetDeleteSmi, SetSetupSmi, SetTearDown), 10]); 11 12 13var SetStringBenchmark = new BenchmarkSuite('Set-String', [1000], [ 14 new Benchmark('Set', false, false, 0, SetAddString, SetSetupStringBase, SetTearDown), 15 new Benchmark('Has', false, false, 0, SetHasString, SetSetupString, SetTearDown), 16 new Benchmark('Delete', false, false, 0, SetDeleteString, SetSetupString, SetTearDown), 17]); 18 19 20var SetObjectBenchmark = new BenchmarkSuite('Set-Object', [1000], [ 21 new Benchmark('Set', false, false, 0, SetAddObject, SetSetupObjectBase, SetTearDown), 22 new Benchmark('Has', false, false, 0, SetHasObject, SetSetupObject, SetTearDown), 23 new Benchmark('Delete', false, false, 0, SetDeleteObject, SetSetupObject, SetTearDown), 24]); 25 26 27var SetIterationBenchmark = new BenchmarkSuite('Set-Iteration', [1000], [ 28 new Benchmark('ForEach', false, false, 0, SetForEach, SetSetupSmi, SetTearDown), 29]); 30 31 32var set; 33 34 35function SetSetupSmiBase() { 36 SetupSmiKeys(); 37 set = new Set; 38} 39 40 41function SetSetupSmi() { 42 SetSetupSmiBase(); 43 SetAddSmi(); 44} 45 46 47function SetSetupStringBase() { 48 SetupStringKeys(); 49 set = new Set; 50} 51 52 53function SetSetupString() { 54 SetSetupStringBase(); 55 SetAddString(); 56} 57 58 59function SetSetupObjectBase() { 60 SetupObjectKeys(); 61 set = new Set; 62} 63 64 65function SetSetupObject() { 66 SetSetupObjectBase(); 67 SetAddObject(); 68} 69 70 71function SetTearDown() { 72 set = null; 73} 74 75 76function SetAddSmi() { 77 for (var i = 0; i < N; i++) { 78 set.add(keys[i], i); 79 } 80} 81 82 83function SetHasSmi() { 84 for (var i = 0; i < N; i++) { 85 if (!set.has(keys[i])) { 86 throw new Error(); 87 } 88 } 89 for (var i = N; i < 2 * N; i++) { 90 if (set.has(keys[i])) { 91 throw new Error(); 92 } 93 } 94} 95 96 97function SetDeleteSmi() { 98 // This is run more than once per setup so we will end up deleting items 99 // more than once. Therefore, we do not the return value of delete. 100 for (var i = 0; i < N; i++) { 101 set.delete(keys[i]); 102 } 103} 104 105 106function SetAddString() { 107 for (var i = 0; i < N; i++) { 108 set.add(keys[i], i); 109 } 110} 111 112 113function SetHasString() { 114 for (var i = 0; i < N; i++) { 115 if (!set.has(keys[i])) { 116 throw new Error(); 117 } 118 } 119 for (var i = N; i < 2 * N; i++) { 120 if (set.has(keys[i])) { 121 throw new Error(); 122 } 123 } 124} 125 126 127function SetDeleteString() { 128 // This is run more than once per setup so we will end up deleting items 129 // more than once. Therefore, we do not the return value of delete. 130 for (var i = 0; i < N; i++) { 131 set.delete(keys[i]); 132 } 133} 134 135 136function SetAddObject() { 137 for (var i = 0; i < N; i++) { 138 set.add(keys[i], i); 139 } 140} 141 142 143function SetHasObject() { 144 for (var i = 0; i < N; i++) { 145 if (!set.has(keys[i])) { 146 throw new Error(); 147 } 148 } 149 for (var i = N; i < 2 * N; i++) { 150 if (set.has(keys[i])) { 151 throw new Error(); 152 } 153 } 154} 155 156 157function SetDeleteObject() { 158 // This is run more than once per setup so we will end up deleting items 159 // more than once. Therefore, we do not the return value of delete. 160 for (var i = 0; i < N; i++) { 161 set.delete(keys[i]); 162 } 163} 164 165 166function SetForEach() { 167 set.forEach(function(v, k) { 168 if (v !== k) { 169 throw new Error(); 170 } 171 }); 172} 173