--- jsr166/src/loops/LoopHelpers.java 2004/04/09 20:12:06 1.1 +++ jsr166/src/loops/LoopHelpers.java 2013/02/16 21:37:44 1.7 @@ -1,10 +1,15 @@ -/** - * Misc utilities in JSR166 performance tests +/* + * Written by Doug Lea with assistance from members of JCP JSR-166 + * Expert Group and released to the public domain, as explained at + * http://creativecommons.org/publicdomain/zero/1.0/ */ import java.util.concurrent.*; import java.util.concurrent.atomic.*; +/** + * Misc utilities in JSR166 performance tests + */ class LoopHelpers { static final SimpleRandom staticRNG = new SimpleRandom(); @@ -12,10 +17,10 @@ class LoopHelpers { // Some mindless computation to do between synchronizations... /** - * generates 32 bit pseudo-random numbers. + * generates 32 bit pseudo-random numbers. * Adapted from http://www.snippets.org */ - public static int compute1(int x) { + public static int compute1(int x) { int lo = 16807 * (x & 0xFFFF); int hi = 16807 * (x >>> 16); lo += (hi & 0x7FFF) << 16; @@ -32,10 +37,10 @@ class LoopHelpers { } /** - * Computes a linear congruential random number a random number - * of times. + * Computes a linear congruential random number a random number + * of times. */ - public static int compute2(int x) { + public static int compute2(int x) { int loops = (x >>> 4) & 7; while (loops-- > 0) { x = (x * 2147483647) % 16807; @@ -43,9 +48,19 @@ class LoopHelpers { return x; } - public static int compute3(int x) { + /** + * Yet another random number generator + */ + public static int compute3(int x) { int t = (x % 127773) * 16807 - (x / 127773) * 2836; - return (t > 0)? t : t + 0x7fffffff; + return (t > 0) ? t : t + 0x7fffffff; + } + + /** + * Yet another random number generator + */ + public static int compute4(int x) { + return x * 134775813 + 1; } /** @@ -53,9 +68,9 @@ class LoopHelpers { * Basically same as java.util.Random. */ public static class SimpleRandom { - private final static long multiplier = 0x5DEECE66DL; - private final static long addend = 0xBL; - private final static long mask = (1L << 48) - 1; + private static final long multiplier = 0x5DEECE66DL; + private static final long addend = 0xBL; + private static final long mask = (1L << 48) - 1; static final AtomicLong seq = new AtomicLong(1); private long seed = System.nanoTime() + seq.getAndIncrement(); @@ -99,5 +114,5 @@ class LoopHelpers { b.replace(b.length()-num.length(), b.length(), num); return b.toString(); } - + }