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

Comparing jsr166/src/test/loops/OfferPollLoops.java (file contents):
Revision 1.2 by jsr166, Thu Oct 29 23:09:07 2009 UTC vs.
Revision 1.12 by jsr166, Sat Dec 31 19:54:17 2016 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.*;
8 < import java.util.concurrent.*;
9 < //import jsr166y.*;
7 > import java.util.Queue;
8 > import java.util.concurrent.ArrayBlockingQueue;
9 > import java.util.concurrent.CyclicBarrier;
10 > import java.util.concurrent.BlockingQueue;
11 > import java.util.concurrent.ConcurrentLinkedDeque;
12 > import java.util.concurrent.ConcurrentLinkedQueue;
13 > import java.util.concurrent.ExecutorService;
14 > import java.util.concurrent.Executors;
15 > import java.util.concurrent.LinkedBlockingDeque;
16 > import java.util.concurrent.LinkedBlockingQueue;
17 > import java.util.concurrent.LinkedTransferQueue;
18 > import java.util.concurrent.Phaser;
19 > import java.util.concurrent.PriorityBlockingQueue;
20  
21   public class OfferPollLoops {
22      static final int NCPUS = Runtime.getRuntime().availableProcessors();
13    static final Random rng = new Random();
23      static final ExecutorService pool = Executors.newCachedThreadPool();
24      static boolean print = false;
25      static int producerSum;
# Line 54 | Line 63 | public class OfferPollLoops {
63  
64          warmup();
65          print = true;
66 <        int k = 1;
58 <        for (int i = 1; i <= maxN;) {
66 >        for (int k = 1, i = 1; i <= maxN;) {
67              System.out.println("Pairs:" + i);
68              oneTest(i, ITERS);
69              if (i == k) {
# Line 103 | Line 111 | public class OfferPollLoops {
111  
112          Thread.sleep(100); // System.gc();
113          if (print)
114 +            System.out.print("ConcurrentLinkedDeque   ");
115 +        oneRun(new ConcurrentLinkedDeque<Integer>(), n, iters);
116 +
117 +        Thread.sleep(100); // System.gc();
118 +        if (print)
119              System.out.print("LinkedBlockingQueue     ");
120          oneRun(new LinkedBlockingQueue<Integer>(), n, iters);
121  
# Line 121 | Line 134 | public class OfferPollLoops {
134              System.out.print("ArrayBlockingQueue      ");
135          oneRun(new ArrayBlockingQueue<Integer>(POOL_SIZE), n, iters);
136  
124
137          Thread.sleep(100); // System.gc();
138          if (print)
139              System.out.print("PriorityBlockingQueue   ");
# Line 131 | Line 143 | public class OfferPollLoops {
143          if (print)
144              System.out.print("ArrayBlockingQueue(fair)");
145          oneRun(new ArrayBlockingQueue<Integer>(POOL_SIZE, true), n, fairIters);
134
146      }
147  
148 <    static abstract class Stage implements Runnable {
148 >    abstract static class Stage implements Runnable {
149          final int iters;
150          final Queue<Integer> queue;
151          final CyclicBarrier barrier;
152          final Phaser lagPhaser;
153 <        Stage (Queue<Integer> q, CyclicBarrier b, Phaser s,
143 <               int iters) {
153 >        Stage(Queue<Integer> q, CyclicBarrier b, Phaser s, int iters) {
154              queue = q;
155              barrier = b;
156              lagPhaser = s;
# Line 233 | Line 243 | public class OfferPollLoops {
243              System.out.println("\t: " + LoopHelpers.rightJustify(time / (iters * n)) + " ns per transfer");
244      }
245  
236
246   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines