ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/StringMapLoops.java
(Generate patch)

Comparing jsr166/src/test/loops/StringMapLoops.java (file contents):
Revision 1.11 by jsr166, Thu Dec 18 18:43:22 2014 UTC vs.
Revision 1.15 by jsr166, Sun Oct 23 03:03:24 2016 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 + import java.io.*;
8 + import java.math.*;
9   import java.util.*;
10   import java.util.concurrent.*;
11  
12   public class StringMapLoops {
13 <    static int nkeys       = 75000;
13 >    static int nkeys       = 147456;
14      static int pinsert     = 60;
15 <    static int premove     =  2;
15 >    static int premove     =  5;
16      static int maxThreads  = 100;
17      static int nops        = 8000000;
18      static int removesPerMaxRandom;
# Line 58 | Line 60 | public class StringMapLoops {
60          System.out.print(" ops: " + nops);
61          System.out.println();
62  
63 <        String[] key = makeKeys(nkeys);
63 >        String[] key = new String[nkeys];
64 >        initStringKeys(key, nkeys);
65 >        //        String[] key = makeKeys(nkeys);
66  
67          int warmups = 2;
68          for (int k = 1, i = 1; i <= maxThreads;) {
# Line 86 | Line 90 | public class StringMapLoops {
90          pool.shutdown();
91      }
92  
89    static String[] makeKeys(int n) {
90        LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom();
91        String[] key = new String[n];
92        for (int i = 0; i < key.length; ++i) {
93            int k = 0;
94            int len = 1 + (rng.next() & 0xf);
95            char[] c = new char[len * 4];
96            for (int j = 0; j < len; ++j) {
97                int r = rng.next();
98                c[k++] = (char) (' ' + (r & 0x7f));
99                r >>>= 8;
100                c[k++] = (char) (' ' + (r & 0x7f));
101                r >>>= 8;
102                c[k++] = (char) (' ' + (r & 0x7f));
103                r >>>= 8;
104                c[k++] = (char) (' ' + (r & 0x7f));
105            }
106            key[i] = new String(c);
107        }
108        return key;
109    }
110
93      static void shuffleKeys(String[] key) {
94          Random rng = new Random();
95          for (int i = key.length; i > 1; --i) {
# Line 120 | Line 102 | public class StringMapLoops {
102  
103      static void test(int i, int nkeys, String[] key, Class<?> mapClass) throws Exception {
104          System.out.print("Threads: " + i + "\t:");
105 <        Map<String, String> map = (Map<String,String>)mapClass.newInstance();
105 >        Map<String, String> map =
106 >            (Map<String,String>) mapClass.getConstructor().newInstance();
107          // Uncomment to start with a non-empty table
108          //        for (int j = 0; j < nkeys; j += 4) // start 1/4 occupied
109          //            map.put(key[j], key[j]);
# Line 147 | Line 130 | public class StringMapLoops {
130          int position;
131          int total;
132  
133 <        Runner(int id, Map<String,String> map, String[] key, CyclicBarrier barrier) {
133 >        Runner(int id, Map<String,String> map, String[] key,  CyclicBarrier barrier) {
134              this.map = map;
135              this.key = key;
136              this.barrier = barrier;
# Line 176 | Line 159 | public class StringMapLoops {
159              }
160              else if (r < insertsPerMaxRandom) {
161                  ++position;
162 +                //                map.putIfAbsent(k, k);
163                  map.put(k, k);
164                  return 2;
165              }
# Line 197 | Line 181 | public class StringMapLoops {
181              }
182          }
183      }
184 +
185 +    static final String wordFile = "testwords.txt";
186 +
187 +    // Read in String keys from file if possible
188 +    static void initStringKeys(String[] keys, int n) throws Exception {
189 +        FileInputStream fr = null;
190 +        try {
191 +            fr = new FileInputStream(wordFile);
192 +        } catch (IOException ex) {
193 +            System.out.println("No word file. Using String.valueOf(i)");
194 +            for (int i = 0; i < n; i++)
195 +                keys[i] = String.valueOf(i);
196 +            return;
197 +        }
198 +
199 +        BufferedInputStream in = new BufferedInputStream(fr);
200 +        int k = 0;
201 +        outer:while (k < n) {
202 +            StringBuffer sb = new StringBuffer();
203 +            for (;;) {
204 +                int c = in.read();
205 +                if (c < 0)
206 +                    break outer;
207 +                char ch = (char) c;
208 +                if (ch == '\n') {
209 +                    keys[k++] = sb.toString();
210 +                    break;
211 +                }
212 +                if (!Character.isWhitespace(ch))
213 +                    sb.append(ch);
214 +            }
215 +        }
216 +        in.close();
217 +
218 +        // fill up remaining keys with path-like compounds of previous pairs
219 +        int j = 0;
220 +        while (k < n)
221 +            keys[k++] = keys[j++] + "/" + keys[j];
222 +    }
223   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines