changeset 349:574c426233cf

Switch to PRNG from "Numerical Recipes": being 32-bit only, provides almost 3x faster Blackholes on 32-bit ARMs.
author shade
date Wed, 15 Jan 2014 18:03:56 +0400
parents b1cb68189284
children 15dc4634cbb8
files jmh-core/src/main/java/org/openjdk/jmh/logic/BlackHole.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java jmh-core/src/test/java/org/openjdk/jmh/BlackholeTest.java
diffstat 3 files changed, 12 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/logic/BlackHole.java	Tue Jan 14 15:54:38 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/logic/BlackHole.java	Wed Jan 15 18:03:56 2014 +0400
@@ -73,8 +73,8 @@
     public volatile Object obj1 = new Object();
     public volatile Object[] objs1 = new Object[]{new Object()};
     public volatile BlackHoleL2 nullBait = null;
-    public long tlr = System.nanoTime();
-    public long tlrMask = 1;
+    public int tlr = (int) System.nanoTime();
+    public int tlrMask = 1;
 }
 
 class BlackHoleL3 extends BlackHoleL2 {
@@ -247,10 +247,10 @@
      */
     public final void consume(Object obj) {
         // let's play the optimizing compiler, dude!
-        long tlr = this.tlr;
-        long tlrMask = this.tlrMask;
+        int tlr = this.tlr;
+        int tlrMask = this.tlrMask;
 
-        tlr = (tlr * 6364136223846793005L + 1442695040888963407L);
+        tlr = (tlr * 1664525 + 1013904223);
         if ((tlr & tlrMask) == 0) {
             // SHOULD ALMOST NEVER HAPPEN IN MEASUREMENT
             this.obj1 = obj;
@@ -267,10 +267,10 @@
      */
     public final void consume(Object[] objs) {
         // let's play the optimizing compiler, dude!
-        long tlr = this.tlr;
-        long tlrMask = this.tlrMask;
+        int tlr = this.tlr;
+        int tlrMask = this.tlrMask;
 
-        tlr = (tlr * 6364136223846793005L + 1442695040888963407L);
+        tlr = (tlr * 1664525 + 1013904223);
         if ((tlr & tlrMask) == 0) {
             // SHOULD ALMOST NEVER HAPPEN IN MEASUREMENT
             this.objs1 = objs;
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Tue Jan 14 15:54:38 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Wed Jan 15 18:03:56 2014 +0400
@@ -874,15 +874,15 @@
         for (Element method : methodGroup.methods()) {
             writer.println("    public " + (methodGroup.isStrictFP() ? "strictfp" : "") + " void " + method.getSimpleName() + "_" + benchmarkKind + "_measurementLoop(InfraControl control, SampleBuffer buffer, " + states.getImplicit("bench").toTypeDef() + ", " + states.getImplicit("blackhole").toTypeDef() + prefix(states.getTypeArgList(method)) + ") throws Throwable {");
             writer.println("        long realTime = 0;");
-            writer.println("        long rnd = System.nanoTime();");
-            writer.println("        long rndMask = 0;");
+            writer.println("        int rnd = (int)System.nanoTime();");
+            writer.println("        int rndMask = 0;");
             writer.println("        long time = 0;");
             writer.println("        int currentStride = 0;");
             writer.println("        do {");
 
             invocationProlog(writer, 3, method, states, true);
 
-            writer.println("            rnd = rnd * 6364136223846793005L + 1442695040888963407L;");
+            writer.println("            rnd = (rnd * 1664525 + 1013904223);");
             writer.println("            boolean sample = (rnd & rndMask) == 0;");
             writer.println("            if (sample) {");
             writer.println("                time = System.nanoTime();");
--- a/jmh-core/src/test/java/org/openjdk/jmh/BlackholeTest.java	Tue Jan 14 15:54:38 2014 +0400
+++ b/jmh-core/src/test/java/org/openjdk/jmh/BlackholeTest.java	Wed Jan 15 18:03:56 2014 +0400
@@ -33,7 +33,7 @@
         long tlr = 0;
         long tlrMask = 0;
         for (int t = 0; t < 1000000000; t++) {
-            tlr = (tlr * 6364136223846793005L + 1442695040888963407L);
+            tlr = (tlr * 1664525 + 1013904223);
             if ((tlr & tlrMask) == 0) {
                 // SHOULD ALMOST NEVER HAPPEN IN MEASUREMENT
                 tlrMask = (tlrMask << 1) + 1;