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/licenses/publicdomain |
5 |
|
*/ |
6 |
|
|
7 |
|
import java.util.concurrent.*; |
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 |
|
} |
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); |
78 |
|
|
79 |
|
static void oneRun(int nThreads, long trialMillis) throws Exception { |
80 |
|
System.out.printf("%4d threads", nThreads); |
82 |
– |
System.out.printf("%9dms", trialMillis); |
81 |
|
Exchanger x = new Exchanger(); |
82 |
|
Runner[] runners = new Runner[nThreads]; |
83 |
|
Thread[] threads = new Thread[nThreads]; |
96 |
|
threads[i].start(); |
97 |
|
} |
98 |
|
Thread.sleep(trialMillis); |
99 |
< |
for (int i = 0; i < nThreads; ++i) |
99 |
> |
for (int i = 0; i < nThreads; ++i) |
100 |
|
threads[i].interrupt(); |
101 |
|
long elapsed = System.nanoTime() - startTime; |
102 |
< |
for (int i = 0; i < nThreads; ++i) |
102 |
> |
for (int i = 0; i < nThreads; ++i) |
103 |
|
threads[i].join(); |
104 |
|
int iters = 1; |
105 |
|
// System.out.println(); |
110 |
|
} |
111 |
|
long rate = iters * 1000L * 1000L * 1000L / elapsed; |
112 |
|
long npt = elapsed / iters; |
113 |
+ |
System.out.printf("%9dms", elapsed / (1000L * 1000L)); |
114 |
|
System.out.printf("%9d it/s ", rate); |
115 |
|
System.out.printf("%9d ns/it", npt); |
116 |
|
System.out.println(); |
117 |
|
// x.printStats(); |
118 |
|
} |
119 |
< |
|
119 |
> |
|
120 |
|
static final class Runner implements Runnable { |
121 |
|
final Exchanger exchanger; |
122 |
|
final Object mine = new Integer(2688); |
141 |
|
} |
142 |
|
} |
143 |
|
} |
145 |
– |
|