Created
June 4, 2017 18:27
-
-
Save qwwdfsad/d393dd7153058710389364a0ae531851 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package playground; | |
import org.openjdk.jmh.annotations.*; | |
import java.util.concurrent.TimeUnit; | |
import java.util.function.Supplier; | |
@BenchmarkMode(Mode.AverageTime) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
@State(Scope.Benchmark) | |
@Fork(value = 2) //, jvmArgsAppend = "-XX:TieredStopAtLevel=1") | |
@Measurement(iterations = 5) | |
@Warmup(iterations = 5) | |
public class CapturingLambda { | |
private Integer param; | |
@Setup | |
public void setup() throws Exception { | |
param = 3; | |
} | |
@Benchmark | |
public Integer returnParam() { | |
return param; | |
} | |
@Benchmark | |
public Integer returnViaClosure() { | |
return call(() -> param); | |
} | |
@CompilerControl(CompilerControl.Mode.INLINE) | |
public Integer call(Supplier<Integer> supplier) { | |
return supplier.get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment