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.8 by jsr166, Tue Nov 3 01:04:02 2009 UTC vs.
Revision 1.18 by jsr166, Sun Oct 23 03:03:23 2016 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.*;
7   import java.io.*;
8   import java.math.*;
9 + import java.util.*;
10  
11   /**
12   * A micro-benchmark with key types and operation mixes roughly
# Line 38 | Line 38 | import java.math.*;
38   public class MapMicroBenchmark {
39      static final String wordFile = "testwords.txt";
40  
41 <    static Class mapClass;
41 >    static Class<?> mapClass;
42      static boolean randomSearches = true;
43  
44      // Nanoseconds per run
# 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 {
150 <        for (int k = 0; k <  nsizes; ++k) {
150 >        for (int k = 0; k < nsizes; ++k) {
151              int len = sizes[k];
152              for (int i = 0; i < jobs.length; i++) {
153                  Thread.sleep(50);
# Line 160 | Line 160 | public class MapMicroBenchmark {
160  
161      // First warmup -- run only mixed job to discourage type specialization
162      static void warmup1(Job job) throws Throwable {
163 <        for (int k = 0; k <  nsizes; ++k)
163 >        for (int k = 0; k < nsizes; ++k)
164              job.work(sizes[k], 1, 1, 0);
165      }
166  
# 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 210 | Line 210 | public class MapMicroBenchmark {
210          System.out.println("\n");
211      }
212  
213
213      static final class Job {
214 <        final String name;
215 <        final Class elementClass;
214 >        final String name;
215 >        final Class<?> elementClass;
216          long[] nanos = new long[nsizes];
217          final Object[] items;
218          Object[] searches;
219          volatile long checkSum;
220          volatile int lastSum;
221 <        Job(String name, Object[] items, Class elementClass) {
221 >        Job(String name, Object[] items, Class<?> elementClass) {
222              this.name = name;
223              this.items = items;
224              this.elementClass = elementClass;
# Line 234 | Line 233 | public class MapMicroBenchmark {
233          }
234  
235          public long work(int len, int minIters, int maxIters, long timeLimit) {
236 <            Map m;
236 >            final Map m;
237              try {
238 <                m = (Map) mapClass.newInstance();
238 >                m = (Map) mapClass.getConstructor().newInstance();
239              } catch (Exception e) {
240                  throw new RuntimeException("Can't instantiate " + mapClass + ": " + e);
241              }
# Line 334 | Line 333 | public class MapMicroBenchmark {
333                      if (m.put(x, x) == null)
334                          ++sum;
335                  }
336 +                /*  // uncomment to avoid calling clear()
337 +                for (int i = 0; i < len; ++i) {
338 +                    Object x = keys[i];
339 +                    m.remove(x);
340 +                }
341 +                */
342                  m.clear();
343                  sum += len - (quarter * 2);
344                  checkSum += sum ^ (sum << 12);
# Line 357 | Line 362 | public class MapMicroBenchmark {
362  
363      }
364  
360
365      static final Random rng = new Random(3122688);
366  
367      // Shuffle the subarrays for each size. This doesn't fully
# Line 377 | Line 381 | public class MapMicroBenchmark {
381  
382      // plain array shuffle
383      static void shuffle(Object[] a, int size) {
384 <        for (int i= size; i>1; i--) {
384 >        for (int i = size; i > 1; i--) {
385              Object t = a[i-1];
386              int r = rng.nextInt(i);
387              a[i-1] = a[r];
# Line 438 | Line 442 | public class MapMicroBenchmark {
442  
443          BufferedInputStream in = new BufferedInputStream(fr);
444          int k = 0;
445 <        outer:while (k < n) {
445 >        outer: while (k < n) {
446              StringBuffer sb = new StringBuffer();
447              for (;;) {
448                  int c = in.read();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines