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

Comparing jsr166/src/test/loops/IntegerMax.java (file contents):
Revision 1.1 by dl, Thu Feb 28 11:41:56 2013 UTC vs.
Revision 1.3 by dl, Fri Mar 22 18:41:30 2013 UTC

# Line 14 | Line 14 | public class IntegerMax {
14      static final AtomicInteger checksum = new AtomicInteger();
15      static boolean print;
16      static boolean allClasses = false; // true if also test dumb/default classes
17 <    static final BinaryOperator<Integer> MAX =
17 >    static final BinaryOperator<Integer> MAX =
18          (Integer x, Integer y) -> x >= y ? x : y;
19  
20      public static void main(String[] args) throws Exception {
# Line 36 | Line 36 | public class IntegerMax {
36          }
37      }
38  
39 <    static String sep() { return print? "\n" : " "; }
39 >    static String sep() { return print ? "\n" : " "; }
40  
41      static void allTests(int size, int trials) throws Exception {
42          System.out.println("---------------------------------------------");
# Line 67 | Line 67 | public class IntegerMax {
67          ctest(new CopyOnWriteArrayList<Integer>(), vlist, vmax, size, trials);
68          ctest(new PriorityQueue<Integer>(), klist, kmax, size, trials);
69          ctest(new PriorityQueue<Integer>(), vlist, vmax, size, trials);
70 +
71          ctest(new HashSet<Integer>(), klist, kmax, size, trials);
72          ctest(new HashSet<Integer>(), vlist, vmax, size, trials);
73          ctest(ConcurrentHashMap.<Integer>newKeySet(), klist, kmax, size, trials);
74          ctest(ConcurrentHashMap.<Integer>newKeySet(), vlist, vmax, size, trials);
75          ctest(new TreeSet<Integer>(), klist, kmax, size, trials);
76          ctest(new TreeSet<Integer>(), vlist, vmax, size, trials);
77 <        ctest(ConcurrentSkipListMap.<Integer>newKeySet(), klist, kmax, size, trials);
78 <        ctest(ConcurrentSkipListMap.<Integer>newKeySet(), vlist, vmax, size, trials);
79 <
77 >        ctest(new ConcurrentSkipListSet<Integer>(), klist, kmax, size, trials);
78 >        ctest(new ConcurrentSkipListSet<Integer>(), vlist, vmax, size, trials);
79 >        
80          mtest(new HashMap<Integer,Integer>(), keys, vals, kmax, vmax, size, trials);
81          mtest(new IdentityHashMap<Integer,Integer>(), keys, vals, kmax, vmax, size, trials);
82          mtest(new WeakHashMap<Integer,Integer>(), keys, vals, kmax, vmax, size, trials);
83          mtest(new ConcurrentHashMap<Integer,Integer>(), keys, vals, kmax, vmax, size, trials);
84 <
84 >        
85          mtest(new TreeMap<Integer,Integer>(), keys, vals, kmax, vmax, size, trials);
86          mtest(new ConcurrentSkipListMap<Integer,Integer>(), keys, vals, kmax, vmax, size, trials);
87 <
87 >    
88          if (allClasses) {
89              mtest(new Hashtable<Integer,Integer>(), keys, vals, kmax, vmax, size, trials);
90              mtest(new LinkedHashMap<Integer,Integer>(), keys, vals, kmax, vmax, size, trials);
# Line 91 | Line 92 | public class IntegerMax {
92              ctest(new LinkedHashSet<Integer>(), vlist, vmax, size, trials);
93              ctest(new LinkedList<Integer>(), klist, kmax, size, trials);
94              ctest(new LinkedList<Integer>(), vlist, vmax, size, trials);
95 +            //            catest(new LinkedList<Integer>(), klist, kmax, size, trials);
96 +            //            catest(new LinkedList<Integer>(), vlist, vmax, size, trials);
97              ctest(new ConcurrentLinkedQueue<Integer>(), klist, kmax, size, trials);
98              ctest(new ConcurrentLinkedQueue<Integer>(), vlist, vmax, size, trials);
99              ctest(new ConcurrentLinkedDeque<Integer>(), klist, kmax, size, trials);
# Line 107 | Line 110 | public class IntegerMax {
110              ctest(new PriorityBlockingQueue<Integer>(SIZE), vlist, vmax, size, trials);
111          }
112  
113 <        if (checksum.get() != 0)
111 <            throw new Error("bad computation");
113 >        if (checksum.get() != 0) throw new Error("bad computation");
114      }
115  
116 <    static void ctest(Collection<Integer> c, List<Integer> klist, int kmax, int size, int trials)
116 >    static void ctest(Collection<Integer> c, List<Integer> klist, int kmax, int size, int trials)
117          throws Exception {
118          String cn = c.getClass().getName();
119          if (cn.startsWith("java.util.concurrent."))
# Line 123 | Line 125 | public class IntegerMax {
125          System.out.print(cn + sep());
126      }
127  
128 +    static void catest(Collection<Integer> c, List<Integer> klist, int kmax, int size, int trials)
129 +        throws Exception {
130 +        String cn = c.getClass().getName();
131 +        if (cn.startsWith("java.util.concurrent."))
132 +            cn = cn.substring(21);
133 +        else if (cn.startsWith("java.util."))
134 +            cn = cn.substring(10);
135 +        cn = cn + ".toArrayList";
136 +        c.addAll(klist);
137 +        ArrayList<Integer> ac = new ArrayList<Integer>(c);
138 +        isptest(ac, kmax, size, trials);
139 +        System.out.print(cn + sep());
140 +    }
141 +
142      static void mtest(Map<Integer,Integer> m, Integer[] keys, Integer[] vals, int kmax, int vmax, int size, int trials) throws Exception {
143          String cn = m.getClass().getName();
144          if (cn.startsWith("java.util.concurrent."))
# Line 141 | Line 157 | public class IntegerMax {
157          long ti = itest(c, max, trials);
158          long ts = stest(c, max, trials);
159          long tp = ptest(c, max, trials);
160 +        if (checksum.get() != 0) throw new Error("bad computation");
161          if (print) {
162              long scale = (long)size * trials;
163              double di = ((double)ti) / scale;
# Line 159 | Line 176 | public class IntegerMax {
176          long tlast =  System.nanoTime();
177          for (int i = 0; i < trials; ++i) {
178              Integer pmax = Integer.valueOf(Integer.MIN_VALUE - checksum.get());
179 <            for (Integer x : c)
179 >            for (Integer x : c)
180                  pmax = MAX.apply(pmax, x);
181              checksum.getAndAdd(max - pmax);
182          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines