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.5 by jsr166, Mon Nov 2 23:42:46 2009 UTC vs.
Revision 1.11 by jsr166, Thu Dec 18 18:43:22 2014 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   import java.util.*;
# Line 20 | Line 20 | public class StringMapLoops {
20  
21      public static void main(String[] args) throws Exception {
22  
23 <        Class mapClass = null;
23 >        Class<?> mapClass = null;
24          if (args.length > 0) {
25              try {
26                  mapClass = Class.forName(args[0]);
# Line 60 | Line 60 | public class StringMapLoops {
60  
61          String[] key = makeKeys(nkeys);
62  
63        int k = 1;
63          int warmups = 2;
64 <        for (int i = 1; i <= maxThreads;) {
64 >        for (int k = 1, i = 1; i <= maxThreads;) {
65              Thread.sleep(100);
66              test(i, nkeys, key, mapClass);
67              shuffleKeys(key);
# Line 96 | Line 95 | public class StringMapLoops {
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));
98 >                c[k++] = (char) (' ' + (r & 0x7f));
99                  r >>>= 8;
100 <                c[k++] = (char)(' ' + (r & 0x7f));
100 >                c[k++] = (char) (' ' + (r & 0x7f));
101                  r >>>= 8;
102 <                c[k++] = (char)(' ' + (r & 0x7f));
102 >                c[k++] = (char) (' ' + (r & 0x7f));
103                  r >>>= 8;
104 <                c[k++] = (char)(' ' + (r & 0x7f));
104 >                c[k++] = (char) (' ' + (r & 0x7f));
105              }
106              key[i] = new String(c);
107          }
# Line 119 | Line 118 | public class StringMapLoops {
118          }
119      }
120  
121 <    static void test(int i, int nkeys, String[] key, Class mapClass) throws Exception {
121 >    static void test(int i, int nkeys, String[] key, Class<?> mapClass) throws Exception {
122          System.out.print("Threads: " + i + "\t:");
123          Map<String, String> map = (Map<String,String>)mapClass.newInstance();
124          // Uncomment to start with a non-empty table
# Line 133 | Line 132 | public class StringMapLoops {
132          barrier.await();
133          barrier.await();
134          long time = timer.getTime();
135 <        long tpo = time / (i * (long)nops);
135 >        long tpo = time / (i * (long) nops);
136          System.out.print(LoopHelpers.rightJustify(tpo) + " ns per op");
137 <        double secs = (double)(time) / 1000000000.0;
137 >        double secs = (double) time / 1000000000.0;
138          System.out.println("\t " + secs + "s run time");
139          map.clear();
140      }
# Line 148 | Line 147 | public class StringMapLoops {
147          int position;
148          int total;
149  
150 <        Runner(int id, Map<String,String> map, String[] key,  CyclicBarrier barrier) {
150 >        Runner(int id, Map<String,String> map, String[] key, CyclicBarrier barrier) {
151              this.map = map;
152              this.key = key;
153              this.barrier = barrier;
# Line 158 | Line 157 | public class StringMapLoops {
157          }
158  
159          int step() {
160 <            // random-walk around key positions,  bunching accesses
160 >            // random-walk around key positions, bunching accesses
161              int r = rng.next();
162              position += (r & 7) - 3;
163              while (position >= key.length) position -= key.length;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines