Merge pull request #9389 from alimate/BAEL-4039

BAEL-4039: Introducing Constant Folding & Dead Code Elimination
This commit is contained in:
Eric Martin 2020-06-02 22:20:38 -05:00 committed by GitHub
commit 5ce70c75de
1 changed files with 47 additions and 1 deletions

View File

@ -1,14 +1,20 @@
package com.baeldung;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hasher;
import com.google.common.hash.Hashing;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.nio.charset.Charset;
import java.util.concurrent.TimeUnit;
public class BenchMark {
@State(Scope.Benchmark)
public static class Log {
public int x = 8;
}
@State(Scope.Benchmark)
public static class ExecutionPlan {
@ -45,4 +51,44 @@ public class BenchMark {
// Do nothing
}
@Benchmark
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
public void doNothing() {
}
@Benchmark
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
public void objectCreation() {
new Object();
}
@Benchmark
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
public Object pillarsOfCreation() {
return new Object();
}
@Benchmark
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
public void blackHole(Blackhole blackhole) {
blackhole.consume(new Object());
}
@Benchmark
public double foldedLog() {
int x = 8;
return Math.log(x);
}
@Benchmark
public double log(Log input) {
return Math.log(input.x);
}
}