Ticket #11768: 0001-Made-Performance-test-use-a-new-random-string-list.patch
File 0001-Made-Performance-test-use-a-new-random-string-list.patch, 5.5 KB (added by , 10 years ago) |
---|
-
test/performance/org/openstreetmap/josm/data/osm/OsmDataGenerator.java
From f1186e6b4404ef138f48ae5e6cb3e3f57c0dc872 Mon Sep 17 00:00:00 2001 From: Michael Zangl <michael.zangl@student.kit.edu> Date: Sat, 8 Aug 2015 13:37:33 +0200 Subject: [PATCH 1/3] Made Performance test use a new random string list. --- .../josm/data/osm/OsmDataGenerator.java | 100 ++++++++++++++++----- 1 file changed, 78 insertions(+), 22 deletions(-) diff --git a/test/performance/org/openstreetmap/josm/data/osm/OsmDataGenerator.java b/test/performance/org/openstreetmap/josm/data/osm/OsmDataGenerator.java index 483967b..29c5ad5 100644
a b public final class OsmDataGenerator { 23 23 } 24 24 25 25 /** 26 * This is a list of randomly generated strings. 27 * <p> 28 * It provides methods to get them both interned and uninterned. 29 * 30 * @author Michael Zangl 31 */ 32 public final static class RandomStringList { 33 private final Random random; 34 private final String[] strings; 35 private final String[] interned; 36 37 /** 38 * Creates a new, random List of Strings. 39 * @param seed The seed to use. 40 * @param size The size of the list. 41 */ 42 public RandomStringList(int seed, int size) { 43 random = new Random(seed); 44 strings = new String[size]; 45 interned = new String[size]; 46 for (int i = 0; i < size; i++) { 47 strings[i] = randomString(); 48 interned[i] = strings[i].intern(); 49 } 50 } 51 52 protected String randomString() { 53 return RandomStringUtils.random(12, 0, 0, true, true, null, random); 54 } 55 56 /** 57 * Gets a String that was not interned. 58 * @return The String. 59 */ 60 public String get() { 61 int n = random.nextInt(strings.length); 62 return strings[n]; 63 } 64 65 /** 66 * Gets a String that was interned. 67 * @return The String. 68 */ 69 public String getInterned() { 70 int n = random.nextInt(interned.length); 71 return interned[n]; 72 } 73 } 74 75 /** 26 76 * A generator that generates test data by filling a data set. 27 77 * @author Michael Zangl 28 78 */ … … public final class OsmDataGenerator { 69 119 return node; 70 120 } 71 121 72 protected String randomString() {73 return RandomStringUtils.random(12, 0, 0, true, true, null, random);74 }75 76 122 /** 77 123 * Gets a file path where this data could be stored. 78 124 * @return A file path. … … public final class OsmDataGenerator { 134 180 private static final int VALUE_COUNT = 200; 135 181 private static final int KEY_COUNT = 150; 136 182 private final double tagNodeRation; 137 private ArrayList<String>keys;138 private ArrayList<String>values;183 private RandomStringList keys; 184 private RandomStringList values; 139 185 140 186 private KeyValueDataGenerator(String datasetName, int nodeCount, double tagNodeRation) { 141 187 super(datasetName, nodeCount); … … public final class OsmDataGenerator { 145 191 @Override 146 192 public void fillData(DataSet ds) { 147 193 super.fillData(ds); 148 keys = new ArrayList<>(); 149 for (int i = 0; i < KEY_COUNT; i++) { 150 keys.add(randomString()); 151 } 152 values = new ArrayList<>(); 153 for (int i = 0; i < VALUE_COUNT; i++) { 154 values.add(randomString()); 155 } 194 keys = new RandomStringList(random.nextInt(), KEY_COUNT); 195 values = new RandomStringList(random.nextInt(), VALUE_COUNT); 156 196 157 197 double tags = nodes.size() * tagNodeRation; 158 198 for (int i = 0; i < tags; i++) { 159 String key = randomKey();160 String value = randomValue();199 String key = keys.get(); 200 String value = values.get(); 161 201 nodes.get(random.nextInt(nodes.size())).put(key, value); 162 202 } 163 203 } 164 204 165 205 /** 206 * Gets the values that were used to fill the tags. 207 * @return The list of strings. 208 */ 209 public RandomStringList randomValues() { 210 ensureInitialized(); 211 return values; 212 } 213 214 /** 215 * Gets the list of keys that was used to fill the tags. 216 * @return The list of strings. 217 */ 218 public RandomStringList randomKeys() { 219 ensureInitialized(); 220 return keys; 221 } 222 223 /** 166 224 * Gets a random value that was used to fill the tags. 167 * @return A random String probably used in as value somewhere. 225 * @return A random String probably used in as value somewhere. Not interned. 168 226 */ 169 227 public String randomValue() { 170 ensureInitialized(); 171 return values.get(random.nextInt(values.size())); 228 return randomValues().get(); 172 229 } 173 230 174 231 /** 175 232 * Gets a random key that was used to fill the tags. 176 * @return A random String probably used in as key somewhere. 233 * @return A random String probably used in as key somewhere. Not interned. 177 234 */ 178 235 public String randomKey() { 179 ensureInitialized(); 180 return keys.get(random.nextInt(keys.size())); 236 return randomKeys().get(); 181 237 } 182 238 } 183 239