Skip to content

Commit

Permalink
make consts not const to prevent const folding
Browse files Browse the repository at this point in the history
  • Loading branch information
isopov committed Apr 14, 2023
1 parent 13c0e59 commit 25cb4b6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/java/io/github/isopov/jmh/MapMapMapBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;


@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
@Fork(3)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
Expand Down Expand Up @@ -62,11 +64,12 @@ interface Tester {
void accept(int first, int second, int third, String value);
}

private static final int FIRSTS = 100;
private static final int SECONDS = 10;
private static final int THIRDS = 10;
//not static, not final to prevent constant folding (see JMHSample_10_ConstantFold)
private int FIRSTS = 100;
private int SECONDS = 10;
private int THIRDS = 10;

private static void test(Tester tester) {
private void test(Tester tester) {
for (int first = 0; first < FIRSTS; first++) {
for (int second = 0; second < SECONDS; second++) {
for (int third = 0; third < THIRDS; third++) {
Expand All @@ -85,3 +88,8 @@ public static void main(String[] args) throws RunnerException {
new Runner(opt).run();
}
}





0 comments on commit 25cb4b6

Please sign in to comment.