
io.dropwizard.metrics5.benchmarks.CachedGaugeBenchmark Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metrics-benchmarks Show documentation
Show all versions of metrics-benchmarks Show documentation
A development module for performance benchmarks of Metrics classes.
package io.dropwizard.metrics5.benchmarks;
import io.dropwizard.metrics5.CachedGauge;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
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;
@State(Scope.Benchmark)
public class CachedGaugeBenchmark {
private CachedGauge cachedGauge = new CachedGauge(100, TimeUnit.MILLISECONDS) {
@Override
protected Integer loadValue() {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
throw new RuntimeException("Thread was interrupted", e);
}
return 12345;
}
};
@Benchmark
public void perfGetValue(Blackhole blackhole) {
blackhole.consume(cachedGauge.getValue());
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + CachedGaugeBenchmark.class.getSimpleName() + ".*")
.warmupIterations(3)
.measurementIterations(5)
.threads(4)
.forks(1)
.build();
new Runner(opt).run();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy