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

Comparing jsr166/src/test/loops/IteratorLoops.java (file contents):
Revision 1.4 by dl, Fri Oct 23 19:57:06 2009 UTC vs.
Revision 1.10 by jsr166, Sun Oct 21 06:40:21 2012 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 14 | Line 14 | import java.util.*;
14   * and long iterators.  Reports include times for adds and other
15   * checks, so overestimate times per iteration.
16   */
17
17   public final class IteratorLoops {
18      static final int DEFAULT_SIZE = 16384;
19      static final int DEFAULT_TRIALS = 4;
# Line 24 | Line 23 | public final class IteratorLoops {
23  
24      public static void main(String[] args) throws Exception {
25          Class klass = Class.forName(args[0]);
26 <        int n = (args.length <= 1)? DEFAULT_SIZE : Integer.parseInt(args[1]);
27 <        int t = (args.length <= 2)? DEFAULT_TRIALS : Integer.parseInt(args[2]);
26 >        int n = (args.length <= 1) ? DEFAULT_SIZE : Integer.parseInt(args[1]);
27 >        int t = (args.length <= 2) ? DEFAULT_TRIALS : Integer.parseInt(args[2]);
28  
29          System.out.print("Class: " + klass.getName());
30 <        System.out.print(" ~iters: " + (long)n * (long)n);
30 >        System.out.print(" ~iters: " + (long) n * (long) n);
31          System.out.print(" trials: " + t);
32          System.out.println();
33  
# Line 38 | Line 37 | public final class IteratorLoops {
37          for (int k = 0; k < colls.length; ++k) {
38              Object x = klass.newInstance();
39              if (x instanceof Collection)
40 <                colls[k] = (Collection<Integer>)x;
40 >                colls[k] = (Collection<Integer>) x;
41              else if (x instanceof Map)
42 <                colls[k] = (Collection<Integer>)Collections.newSetFromMap((Map)x);
42 >                colls[k] = (Collection<Integer>)
43 >                    Collections.newSetFromMap((Map) x);
44              else
45                  throw new Error("bad class");
46          }
# Line 64 | Line 64 | public final class IteratorLoops {
64          preload(n);
65          long startTime = System.nanoTime();
66          long count = traversals(n);
67 <        double elapsed = (double)(System.nanoTime() - startTime);
67 >        double elapsed = (double) (System.nanoTime() - startTime);
68          double npi = elapsed / count;
69          double secs = elapsed / 1000000000;
70          System.out.printf("%7.1f ns/iter  %8.3fs run time\n", npi, secs);
# Line 73 | Line 73 | public final class IteratorLoops {
73      long traversals(int n) {
74          long count = 0;
75          long check = 0;
76 <        for (int i = 0; i < n; i++) {
76 >        for (int i = 0; i < n; i++) {
77              check += elementCount;
78              count += counts();
79              maybeAdd();
# Line 119 | Line 119 | public final class IteratorLoops {
119              k >>>= 1;
120          }
121          // let GC settle down
122 <        try { Thread.sleep(500); } catch(Exception ex) { return; }
122 >        try { Thread.sleep(500); }
123 >        catch (Exception ex) { return; }
124      }
125  
126  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines