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

Comparing jsr166/src/test/loops/SpinningTieredPhaserLoops.java (file contents):
Revision 1.1 by dl, Sun Nov 1 21:28:57 2009 UTC vs.
Revision 1.5 by jsr166, Tue Mar 15 19:47:06 2011 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 21 | Line 21 | public class SpinningTieredPhaserLoops {
21      static final long NPS = (1000L * 1000 * 1000);
22  
23      static int tasksPerPhaser = Math.max(NCPUS / 4, 4);
24 <    
24 >
25      static void build(Runnable[] actions, int sz, int lo, int hi, Phaser b) {
26 <        int step = (hi - lo) / tasksPerPhaser;
27 <        if (step > 1) {
28 <            int i = lo;
29 <            while (i < hi) {
30 <                int r = Math.min(i + step, hi);
31 <                build(actions, sz, i, r, new Phaser(b));
32 <                i = r;
26 >        if (hi - lo > tasksPerPhaser) {
27 >            for (int i = lo; i < hi; i += tasksPerPhaser) {
28 >                int j = Math.min(i + tasksPerPhaser, hi);
29 >                build(actions, sz, i, j, new Phaser(b));
30              }
31 <        }
32 <        else {
36 <            for (int i = lo; i < hi; ++i)
31 >        } else {
32 >            for (int i = lo; i < hi; ++i)
33                  actions[i] = new PhaserAction(i, b, sz);
34          }
35      }
# Line 53 | Line 49 | public class SpinningTieredPhaserLoops {
49          public void run() {
50              int n = size;
51              Phaser b = phaser;
52 <            for(int i = 0; i < n; ++i) {
52 >            for (int i = 0; i < n; ++i) {
53                  int p = b.arrive();
54                  while (b.getPhase() == p) {
55                      if ((ThreadLocalRandom.current().nextInt() & 127) == 0)
# Line 69 | Line 65 | public class SpinningTieredPhaserLoops {
65              nthreads = Integer.parseInt(args[0]);
66          if (args.length > 1)
67              tasksPerPhaser = Integer.parseInt(args[1]);
68 <            
68 >
69          System.out.printf("Max %d Threads, %d tasks per phaser\n", nthreads, tasksPerPhaser);
70  
71          for (int k = 2; k <= nthreads; k *= 2) {
72              for (int size = FIRST_SIZE; size <= LAST_SIZE; size *= 10) {
73                  long startTime = System.nanoTime();
74 <                
74 >
75                  Runnable[] actions = new Runnable [k];
76                  build(actions, size, 0, k, new Phaser());
77                  Future[] futures = new Future[k];
# Line 93 | Line 89 | public class SpinningTieredPhaserLoops {
89          }
90          pool.shutdown();
91      }
96    
97 }
98
92  
93 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines