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 com.elastic; | |
import org.openjdk.jmh.annotations.*; | |
import org.openjdk.jmh.infra.Blackhole; | |
import org.openjdk.jmh.profile.GCProfiler; | |
import org.openjdk.jmh.runner.Runner; | |
import org.openjdk.jmh.runner.RunnerException; | |
import org.openjdk.jmh.runner.options.Options; | |
import org.openjdk.jmh.runner.options.OptionsBuilder; | |
import java.util.concurrent.TimeUnit; | |
@BenchmarkMode(Mode.AverageTime) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
@Fork(1) | |
@Warmup(iterations = 5, time = 5000, timeUnit = TimeUnit.MILLISECONDS) | |
@Measurement(iterations = 5, time = 5000, timeUnit = TimeUnit.MILLISECONDS) | |
@State(Scope.Benchmark) | |
public class PartialEATest { | |
@Param(value = {"1"}) | |
private int value; | |
@Benchmark | |
public void allocate(Blackhole bh) { | |
checkArg(value > 0, "expected non-negative value: %s, %s", value, 1000, "A", 700); | |
} | |
public static void checkArg(boolean cond, String msg, Object ... args){ | |
if (!cond){ | |
String format = String.format(msg, args); | |
throw new IllegalArgumentException(format); | |
} | |
} | |
public static void main(String[] args) throws RunnerException { | |
Options opt = new OptionsBuilder() | |
.include(PartialEATest.class.getSimpleName()) | |
.addProfiler(GCProfiler.class) | |
.build(); | |
new Runner(opt).run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment