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

Comparing jsr166/src/loops/LoopHelpers.java (file contents):
Revision 1.1 by jsr166, Fri Apr 9 20:12:06 2004 UTC vs.
Revision 1.7 by jsr166, Sat Feb 16 21:37:44 2013 UTC

# Line 1 | Line 1
1 < /**
2 < * Misc utilities in JSR166 performance tests
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/publicdomain/zero/1.0/
5   */
6  
7   import java.util.concurrent.*;
8   import java.util.concurrent.atomic.*;
9  
10 + /**
11 + * Misc utilities in JSR166 performance tests
12 + */
13   class LoopHelpers {
14  
15      static final SimpleRandom staticRNG = new SimpleRandom();
# Line 12 | Line 17 | class LoopHelpers {
17      // Some mindless computation to do between synchronizations...
18  
19      /**
20 <     * generates 32 bit pseudo-random numbers.
20 >     * generates 32 bit pseudo-random numbers.
21       * Adapted from http://www.snippets.org
22       */
23 <    public static int compute1(int x) {
23 >    public static int compute1(int x) {
24          int lo = 16807 * (x & 0xFFFF);
25          int hi = 16807 * (x >>> 16);
26          lo += (hi & 0x7FFF) << 16;
# Line 32 | Line 37 | class LoopHelpers {
37      }
38  
39      /**
40 <     *  Computes a linear congruential random number a random number
41 <     *  of times.
40 >     * Computes a linear congruential random number a random number
41 >     * of times.
42       */
43 <    public static int compute2(int x) {
43 >    public static int compute2(int x) {
44          int loops = (x >>> 4) & 7;
45          while (loops-- > 0) {
46              x = (x * 2147483647) % 16807;
# Line 43 | Line 48 | class LoopHelpers {
48          return x;
49      }
50  
51 <    public static int compute3(int x) {
51 >    /**
52 >     * Yet another random number generator
53 >     */
54 >    public static int compute3(int x) {
55          int t = (x % 127773) * 16807 - (x / 127773) * 2836;
56 <        return (t > 0)? t : t + 0x7fffffff;
56 >        return (t > 0) ? t : t + 0x7fffffff;
57 >    }
58 >
59 >    /**
60 >     * Yet another random number generator
61 >     */
62 >    public static int compute4(int x) {
63 >        return x * 134775813 + 1;
64      }
65  
66      /**
# Line 53 | Line 68 | class LoopHelpers {
68       * Basically same as java.util.Random.
69       */
70      public static class SimpleRandom {
71 <        private final static long multiplier = 0x5DEECE66DL;
72 <        private final static long addend = 0xBL;
73 <        private final static long mask = (1L << 48) - 1;
71 >        private static final long multiplier = 0x5DEECE66DL;
72 >        private static final long addend = 0xBL;
73 >        private static final long mask = (1L << 48) - 1;
74          static final AtomicLong seq = new AtomicLong(1);
75          private long seed = System.nanoTime() + seq.getAndIncrement();
76  
# Line 99 | Line 114 | class LoopHelpers {
114          b.replace(b.length()-num.length(), b.length(), num);
115          return b.toString();
116      }
117 <  
117 >
118   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines