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 michael2402, 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 {  
    2323    }
    2424
    2525    /**
     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    /**
    2676     * A generator that generates test data by filling a data set.
    2777     * @author Michael Zangl
    2878     */
    public final class OsmDataGenerator {  
    69119            return node;
    70120        }
    71121
    72         protected String randomString() {
    73             return RandomStringUtils.random(12, 0, 0, true, true, null, random);
    74         }
    75 
    76122        /**
    77123         * Gets a file path where this data could be stored.
    78124         * @return A file path.
    public final class OsmDataGenerator {  
    134180        private static final int VALUE_COUNT = 200;
    135181        private static final int KEY_COUNT = 150;
    136182        private final double tagNodeRation;
    137         private ArrayList<String> keys;
    138         private ArrayList<String> values;
     183        private RandomStringList keys;
     184        private RandomStringList values;
    139185
    140186        private KeyValueDataGenerator(String datasetName, int nodeCount, double tagNodeRation) {
    141187            super(datasetName, nodeCount);
    public final class OsmDataGenerator {  
    145191        @Override
    146192        public void fillData(DataSet ds) {
    147193            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);
    156196
    157197            double tags = nodes.size() * tagNodeRation;
    158198            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();
    161201                nodes.get(random.nextInt(nodes.size())).put(key, value);
    162202            }
    163203        }
    164204
    165205        /**
     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        /**
    166224         * 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.
    168226         */
    169227        public String randomValue() {
    170             ensureInitialized();
    171             return values.get(random.nextInt(values.size()));
     228            return randomValues().get();
    172229        }
    173230
    174231        /**
    175232         * 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.
    177234         */
    178235        public String randomKey() {
    179             ensureInitialized();
    180             return keys.get(random.nextInt(keys.size()));
     236            return randomKeys().get();
    181237        }
    182238    }
    183239