Skip to content

Instantly share code, notes, and snippets.

@vladimirdolzhenko
Created April 6, 2018 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladimirdolzhenko/938877e2cb309006464608cc20d1667c to your computer and use it in GitHub Desktop.
Save vladimirdolzhenko/938877e2cb309006464608cc20d1667c to your computer and use it in GitHub Desktop.
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