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 MapSmiBenchmark = new BenchmarkSuite('Map-Smi', [1000], [ 7 new Benchmark('Set', false, false, 0, MapSetSmi, MapSetupSmiBase, MapTearDown), 8 new Benchmark('Has', false, false, 0, MapHasSmi, MapSetupSmi, MapTearDown), 9 new Benchmark('Get', false, false, 0, MapGetSmi, MapSetupSmi, MapTearDown), 10 new Benchmark('Delete', false, false, 0, MapDeleteSmi, MapSetupSmi, MapTearDown), 11]); 12 13 14var MapStringBenchmark = new BenchmarkSuite('Map-String', [1000], [ 15 new Benchmark('Set', false, false, 0, MapSetString, MapSetupStringBase, MapTearDown), 16 new Benchmark('Has', false, false, 0, MapHasString, MapSetupString, MapTearDown), 17 new Benchmark('Get', false, false, 0, MapGetString, MapSetupString, MapTearDown), 18 new Benchmark('Delete', false, false, 0, MapDeleteString, MapSetupString, MapTearDown), 19]); 20 21 22var MapObjectBenchmark = new BenchmarkSuite('Map-Object', [1000], [ 23 new Benchmark('Set', false, false, 0, MapSetObject, MapSetupObjectBase, MapTearDown), 24 new Benchmark('Has', false, false, 0, MapHasObject, MapSetupObject, MapTearDown), 25 new Benchmark('Get', false, false, 0, MapGetObject, MapSetupObject, MapTearDown), 26 new Benchmark('Delete', false, false, 0, MapDeleteObject, MapSetupObject, MapTearDown), 27]); 28 29 30var MapIterationBenchmark = new BenchmarkSuite('Map-Iteration', [1000], [ 31 new Benchmark('ForEach', false, false, 0, MapForEach, MapSetupSmi, MapTearDown), 32]); 33 34 35var map; 36 37 38function MapSetupSmiBase() { 39 SetupSmiKeys(); 40 map = new Map; 41} 42 43 44function MapSetupSmi() { 45 MapSetupSmiBase(); 46 MapSetSmi(); 47} 48 49 50function MapSetupStringBase() { 51 SetupStringKeys(); 52 map = new Map; 53} 54 55 56function MapSetupString() { 57 MapSetupStringBase(); 58 MapSetString(); 59} 60 61 62function MapSetupObjectBase() { 63 SetupObjectKeys(); 64 map = new Map; 65} 66 67 68function MapSetupObject() { 69 MapSetupObjectBase(); 70 MapSetObject(); 71} 72 73 74function MapTearDown() { 75 map = null; 76} 77 78 79function MapSetSmi() { 80 for (var i = 0; i < N; i++) { 81 map.set(keys[i], i); 82 } 83} 84 85 86function MapHasSmi() { 87 for (var i = 0; i < N; i++) { 88 if (!map.has(keys[i])) { 89 throw new Error(); 90 } 91 } 92 for (var i = N; i < 2 * N; i++) { 93 if (map.has(keys[i])) { 94 throw new Error(); 95 } 96 } 97} 98 99 100function MapGetSmi() { 101 for (var i = 0; i < N; i++) { 102 if (map.get(keys[i]) !== i) { 103 throw new Error(); 104 } 105 } 106 for (var i = N; i < 2 * N; i++) { 107 if (map.get(keys[i]) !== undefined) { 108 throw new Error(); 109 } 110 } 111} 112 113 114function MapDeleteSmi() { 115 // This is run more than once per setup so we will end up deleting items 116 // more than once. Therefore, we do not the return value of delete. 117 for (var i = 0; i < N; i++) { 118 map.delete(keys[i]); 119 } 120} 121 122 123function MapSetString() { 124 for (var i = 0; i < N; i++) { 125 map.set(keys[i], i); 126 } 127} 128 129 130function MapHasString() { 131 for (var i = 0; i < N; i++) { 132 if (!map.has(keys[i])) { 133 throw new Error(); 134 } 135 } 136 for (var i = N; i < 2 * N; i++) { 137 if (map.has(keys[i])) { 138 throw new Error(); 139 } 140 } 141} 142 143 144function MapGetString() { 145 for (var i = 0; i < N; i++) { 146 if (map.get(keys[i]) !== i) { 147 throw new Error(); 148 } 149 } 150 for (var i = N; i < 2 * N; i++) { 151 if (map.get(keys[i]) !== undefined) { 152 throw new Error(); 153 } 154 } 155} 156 157 158function MapDeleteString() { 159 // This is run more than once per setup so we will end up deleting items 160 // more than once. Therefore, we do not the return value of delete. 161 for (var i = 0; i < N; i++) { 162 map.delete(keys[i]); 163 } 164} 165 166 167function MapSetObject() { 168 for (var i = 0; i < N; i++) { 169 map.set(keys[i], i); 170 } 171} 172 173 174function MapHasObject() { 175 for (var i = 0; i < N; i++) { 176 if (!map.has(keys[i])) { 177 throw new Error(); 178 } 179 } 180 for (var i = N; i < 2 * N; i++) { 181 if (map.has(keys[i])) { 182 throw new Error(); 183 } 184 } 185} 186 187 188function MapGetObject() { 189 for (var i = 0; i < N; i++) { 190 if (map.get(keys[i]) !== i) { 191 throw new Error(); 192 } 193 } 194 for (var i = N; i < 2 * N; i++) { 195 if (map.get(keys[i]) !== undefined) { 196 throw new Error(); 197 } 198 } 199} 200 201 202function MapDeleteObject() { 203 // This is run more than once per setup so we will end up deleting items 204 // more than once. Therefore, we do not the return value of delete. 205 for (var i = 0; i < N; i++) { 206 map.delete(keys[i]); 207 } 208} 209 210 211function MapForEach() { 212 map.forEach(function(v, k) { 213 if (v !== k) { 214 throw new Error(); 215 } 216 }); 217} 218