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

Comparing jsr166/src/test/loops/ExchangeLoops.java (file contents):
Revision 1.2 by dl, Mon Feb 13 12:39:23 2006 UTC vs.
Revision 1.10 by jsr166, Thu Jan 15 18:34:19 2015 UTC

# Line 1 | Line 1
1   /*
2   * Written by Bill Scherer and Doug Lea with assistance from members
3 < * of JCP JSR-166 Expert Group and released to the public domain. Use,
4 < * modify, and redistribute this code in any way without
5 < * acknowledgement.
3 > * of JCP JSR-166 Expert Group and released to the public domain, as
4 > * explained at http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   import java.util.concurrent.*;
# Line 13 | Line 12 | public class ExchangeLoops {
12      static final int NCPUS = Runtime.getRuntime().availableProcessors();
13  
14      static final int  DEFAULT_THREADS = NCPUS + 2;
15 <    static final long DEFAULT_TRIAL_MILLIS   = 10000;
15 >    static final long DEFAULT_TRIAL_MILLIS = 10000;
16  
17      public static void main(String[] args) throws Exception {
18          int maxThreads = DEFAULT_THREADS;
# Line 28 | Line 27 | public class ExchangeLoops {
27                  trialMillis = Integer.parseInt(args[argc]);
28              else if (option.equals("-r"))
29                  nReps = Integer.parseInt(args[argc]);
30 <            else
30 >            else
31                  maxThreads = Integer.parseInt(option);
32              argc++;
33          }
34  
35 <        // Display runtime parameters
36 <        System.out.print("ExchangeTest");
37 <        System.out.print(" -t " + trialMillis);
35 >        // Display runtime parameters
36 >        System.out.print("ExchangeTest");
37 >        System.out.print(" -t " + trialMillis);
38          System.out.print(" -r " + nReps);
39 <        System.out.print(" max threads " + maxThreads);
40 <        System.out.println();
39 >        System.out.print(" max threads " + maxThreads);
40 >        System.out.println();
41          long warmupTime = 2000;
42          long sleepTime = 100;
43 <        int nw = maxThreads >= 3? 3 : 2;
43 >        int nw = (maxThreads >= 3) ? 3 : 2;
44  
45          System.out.println("Warmups..");
46          oneRun(3, warmupTime);
# Line 74 | Line 73 | public class ExchangeLoops {
73              Thread.sleep(sleepTime);
74          }
75  
77
76      }
77  
78      static void oneRun(int nThreads, long trialMillis) throws Exception {
79          System.out.printf("%4d threads", nThreads);
82        System.out.printf("%9dms", trialMillis);
80          Exchanger x = new Exchanger();
81          Runner[] runners = new Runner[nThreads];
82          Thread[] threads = new Thread[nThreads];
# Line 98 | Line 95 | public class ExchangeLoops {
95              threads[i].start();
96          }
97          Thread.sleep(trialMillis);
98 <        for (int i = 0; i < nThreads; ++i)
98 >        for (int i = 0; i < nThreads; ++i)
99              threads[i].interrupt();
100          long elapsed = System.nanoTime() - startTime;
101 <        for (int i = 0; i < nThreads; ++i)
101 >        for (int i = 0; i < nThreads; ++i)
102              threads[i].join();
103          int iters = 1;
104          //        System.out.println();
# Line 112 | Line 109 | public class ExchangeLoops {
109          }
110          long rate = iters * 1000L * 1000L * 1000L / elapsed;
111          long npt = elapsed / iters;
112 +        System.out.printf("%9dms", elapsed / (1000L * 1000L));
113          System.out.printf("%9d it/s ", rate);
114          System.out.printf("%9d ns/it", npt);
115          System.out.println();
116          //        x.printStats();
117      }
118 <      
118 >
119      static final class Runner implements Runnable {
120          final Exchanger exchanger;
121          final Object mine = new Integer(2688);
# Line 142 | Line 140 | public class ExchangeLoops {
140          }
141      }
142   }
145        

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines