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.3 by dl, Sun Jul 26 15:40:47 2009 UTC vs.
Revision 1.4 by jsr166, Thu Oct 29 23:09:07 2009 UTC

# Line 11 | Line 11 | import java.math.*;
11   /**
12   * A micro-benchmark with key types and operation mixes roughly
13   * corresponding to some real programs.
14 < *
14 > *
15   * The main results are a table of approximate nanoseconds per
16   * element-operation (averaged across get, put etc) for each type,
17   * across a range of map sizes. It also includes category "Mixed"
# Line 24 | Line 24 | import java.math.*;
24   * dynamic type specialization.  Some test classes, like Float and
25   * BigDecimal are included not because they are commonly used as keys,
26   * but because they can be problematic for some map implementations.
27 < *
27 > *
28   * By default, it creates and inserts in order dense numerical keys
29   * and searches for keys in scrambled order. Use "s" as second arg to
30   * instead insert and search in unscrambled order.
# Line 61 | Line 61 | public class MapMicroBenchmark {
61              System.out.println("Usage: java MapMicroBenchmark className [r|s]keys [r|s]searches");
62              return;
63          }
64 <            
64 >
65          mapClass = Class.forName(args[0]);
66  
67          if (args.length > 1) {
# Line 261 | Line 261 | public class MapMicroBenchmark {
261                  sum += len - half;
262                  for (int i = 0; i < len; ++i) {
263                      Object x = keys[i];
264 <                    Object v = m.get(x);
264 >                    Object v = m.get(x);
265                      if (elementClass.isInstance(v)) // touch v
266                          ++sum;
267                  }
# Line 273 | Line 273 | public class MapMicroBenchmark {
273                  }
274                  checkSum += sum ^ (sum << 3);
275                  for (Object e : m.keySet()) {
276 <                    if (elementClass.isInstance(e))
276 >                    if (elementClass.isInstance(e))
277                          ++sum;
278                  }
279                  checkSum += sum ^ (sum << 4);
280                  for (Object e : m.values()) {
281 <                    if (elementClass.isInstance(e))
281 >                    if (elementClass.isInstance(e))
282                          ++sum;
283                  }
284                  checkSum += sum ^ (sum << 5);
# Line 340 | Line 340 | public class MapMicroBenchmark {
340  
341                  if (j == 0 && sum != lastSum + len * OPS_PER_ITER)
342                      throw new Error(name);
343 <                
343 >
344                  elapsed = System.nanoTime() - startTime;
345                  ++j;
346                  if (j >= minIters &&
347                      (j >= maxIters || elapsed >= timeLimit))
348                      break;
349                  // non-warmup - swap some keys for next insert
350 <                if (minIters != 1 && randomSearches)
350 >                if (minIters != 1 && randomSearches)
351                      shuffleSome(ins, len, len >>> 3);
352              }
353              long ops = ((long)j) * len * OPS_PER_ITER;
# Line 373 | Line 373 | public class MapMicroBenchmark {
373                  a[r] = t;
374              }
375          }
376 <    }            
376 >    }
377  
378      // plain array shuffle
379      static void shuffle(Object[] a, int size) {
# Line 425 | Line 425 | public class MapMicroBenchmark {
425      }
426  
427      // Read in String keys from file if possible
428 <    static void initStringKeys(Object[] keys, int n) throws Exception {
428 >    static void initStringKeys(Object[] keys, int n) throws Exception {
429          FileInputStream fr = null;
430          try {
431              fr = new FileInputStream(wordFile);
# Line 442 | Line 442 | public class MapMicroBenchmark {
442              StringBuffer sb = new StringBuffer();
443              for (;;) {
444                  int c = in.read();
445 <                if (c < 0)
445 >                if (c < 0)
446                      break outer;
447                  char ch = (char)c;
448                  if (ch == '\n') {
# Line 462 | Line 462 | public class MapMicroBenchmark {
462      }
463  
464   }
465

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines