Skip to content

Commit 56f5c29

Browse files
committed
Use different data in GCD benchmarks on each iteration
1 parent 4f56121 commit 56f5c29

File tree

1 file changed

+9
-4
lines changed
  • commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/core

1 file changed

+9
-4
lines changed

commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/core/GcdPerformance.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.openjdk.jmh.annotations.Benchmark;
2323
import org.openjdk.jmh.annotations.BenchmarkMode;
2424
import org.openjdk.jmh.annotations.Fork;
25+
import org.openjdk.jmh.annotations.Level;
2526
import org.openjdk.jmh.annotations.Measurement;
2627
import org.openjdk.jmh.annotations.Mode;
2728
import org.openjdk.jmh.annotations.Param;
@@ -58,7 +59,7 @@ public static class Ints {
5859
/**
5960
* The number of number pairs to generate.
6061
*/
61-
@Param("1000")
62+
@Param("100000")
6263
private int numPairs;
6364

6465
/**
@@ -69,12 +70,14 @@ public static class Ints {
6970
/**
7071
* JMH setup method to generate the data.
7172
*/
72-
@Setup
73+
@Setup(Level.Iteration)
7374
public void setup() {
7475
values = getRandomProvider(seed).ints()
7576
.filter(i -> i != Integer.MIN_VALUE).
7677
limit(numPairs * 2)
7778
.toArray();
79+
80+
seed = (((long) values[0]) << Integer.SIZE) | values[1];
7881
}
7982
}
8083

@@ -92,7 +95,7 @@ public static class Longs {
9295
/**
9396
* The number of number pairs to generate.
9497
*/
95-
@Param("1000")
98+
@Param("100000")
9699
private int numPairs;
97100

98101
/**
@@ -103,12 +106,14 @@ public static class Longs {
103106
/**
104107
* JMH setup method to generate the data.
105108
*/
106-
@Setup
109+
@Setup(Level.Iteration)
107110
public void setup() {
108111
values = getRandomProvider(seed).longs()
109112
.filter(i -> i != Long.MIN_VALUE)
110113
.limit(numPairs * 2)
111114
.toArray();
115+
116+
seed = values[0];
112117
}
113118
}
114119

0 commit comments

Comments
 (0)