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

Comparing jsr166/src/test/loops/MapMicroBenchmark.java (file contents):
Revision 1.4 by jsr166, Thu Oct 29 23:09:07 2009 UTC vs.
Revision 1.10 by jsr166, Tue Mar 15 19:47:05 2011 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 31 | Line 31 | import java.math.*;
31   *
32   * For String keys, the program tries to use file "testwords.txt", which
33   * is best used with real words.  We can't check in this file, but you
34 < * can create one from a real dictonary (1 line per word) and then run
34 > * can create one from a real dictionary (1 line per word) and then run
35   * linux "shuf" to randomize entries. If no file exists, it uses
36   * String.valueOf(i) for element i.
37   */
# Line 102 | Line 102 | public class MapMicroBenchmark {
102          jobs[2] = new Job("Integer   ", is, Integer.class);
103  
104          Object[] ls = new Object[n];
105 <        for (int i = 0; i < n; i++) ls[i] = Long.valueOf((long)i);
105 >        for (int i = 0; i < n; i++) ls[i] = Long.valueOf((long) i);
106          jobs[3] = new Job("Long      ", ls, Long.class);
107  
108          Object[] fs = new Object[n];
109 <        for (int i = 0; i < n; i++) fs[i] = Float.valueOf((float)i);
109 >        for (int i = 0; i < n; i++) fs[i] = Float.valueOf((float) i);
110          jobs[4] = new Job("Float     ", fs, Float.class);
111  
112          Object[] ds = new Object[n];
113 <        for (int i = 0; i < n; i++) ds[i] = Double.valueOf((double)i);
113 >        for (int i = 0; i < n; i++) ds[i] = Double.valueOf((double) i);
114          jobs[5] = new Job("Double    ", ds, Double.class);
115  
116          Object[] bs = new Object[n];
# Line 143 | Line 143 | public class MapMicroBenchmark {
143          warmup1(mixed);
144          warmup3(jobs);
145          Thread.sleep(500);
146 <        time(jobs);
146 >        time(jobs);
147      }
148  
149      static void runWork(Job[] jobs, int minIters, int maxIters, long timeLimit) throws Throwable {
# Line 193 | Line 193 | public class MapMicroBenchmark {
193          long[] aves = new long[nsizes];
194          int njobs = jobs.length;
195  
196 <        for (int i = 0; i < njobs; i++) {
196 >        for (int i = 0; i < njobs; i++) {
197              System.out.print(jobs[i].name);
198              for (int k = 0; k < nsizes; ++k) {
199                  long nanos = jobs[i].nanos[k];
# Line 212 | Line 212 | public class MapMicroBenchmark {
212  
213  
214      static final class Job {
215 <        final String name;
215 >        final String name;
216          final Class elementClass;
217          long[] nanos = new long[nsizes];
218          final Object[] items;
# Line 236 | Line 236 | public class MapMicroBenchmark {
236          public long work(int len, int minIters, int maxIters, long timeLimit) {
237              Map m;
238              try {
239 <                m = (Map)mapClass.newInstance();
240 <            } catch(Exception e) {
239 >                m = (Map) mapClass.newInstance();
240 >            } catch (Exception e) {
241                  throw new RuntimeException("Can't instantiate " + mapClass + ": " + e);
242              }
243              Object[] ins = items;
# Line 350 | Line 350 | public class MapMicroBenchmark {
350                  if (minIters != 1 && randomSearches)
351                      shuffleSome(ins, len, len >>> 3);
352              }
353 <            long ops = ((long)j) * len * OPS_PER_ITER;
353 >            long ops = ((long) j) * len * OPS_PER_ITER;
354              lastSum = sum;
355              return elapsed / ops;
356          }
# Line 365 | Line 365 | public class MapMicroBenchmark {
365      // more realistic
366      static void scramble(Object[] a) {
367          for (int k = 0; k < sizes.length; ++k) {
368 <            int origin = k == 0? 0 : sizes[k-1];
368 >            int origin = (k == 0) ? 0 : sizes[k-1];
369              for (int i = sizes[k]; i > origin + 1; i--) {
370                  Object t = a[i-1];
371                  int r = rng.nextInt(i - origin) + origin;
# Line 444 | Line 444 | public class MapMicroBenchmark {
444                  int c = in.read();
445                  if (c < 0)
446                      break outer;
447 <                char ch = (char)c;
447 >                char ch = (char) c;
448                  if (ch == '\n') {
449                      keys[k++] = sb.toString();
450                      break;
# Line 458 | Line 458 | public class MapMicroBenchmark {
458          // fill up remaining keys with path-like compounds of previous pairs
459          int j = 0;
460          while (k < n)
461 <            keys[k++] = (String)keys[j++] + "/" + (String)keys[j];
461 >            keys[k++] = (String) keys[j++] + "/" + (String) keys[j];
462      }
463  
464   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines