All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dropwizard.metrics5.benchmarks.CounterBenchmark Maven / Gradle / Ivy

There is a newer version: 5.0.0-rc24
Show newest version
package io.dropwizard.metrics5.benchmarks;

import io.dropwizard.metrics5.Counter;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
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;

@State(Scope.Benchmark)
public class CounterBenchmark {

    private final Counter counter = new Counter();

    // It's intentionally not declared as final to avoid constant folding
    private long nextValue = 0xFBFBABBA;

    @Benchmark
    public Object perfIncrement() {
        counter.inc(nextValue); 
        return counter;
    }

    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .include(".*" + CounterBenchmark.class.getSimpleName() + ".*")
                .warmupIterations(3)
                .measurementIterations(5)
                .threads(4)
                .forks(1)
                .build();

        new Runner(opt).run();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy