com.alibaba.csp.sentinel.benchmark.RollingNumberBenchmark Maven / Gradle / Ivy
package com.alibaba.csp.sentinel.benchmark;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
/**
* @author Eric Zhao
*/
@Warmup(iterations = 10)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@State(Scope.Benchmark)
public class RollingNumberBenchmark {
private final HystrixRollingNumber rollingNumber = new HystrixRollingNumber(1000, 10);
@Benchmark
@Threads(8)
public void testMultiThreadUpdate(Blackhole blackhole) {
blackhole.consume(rollingNumber.getCurrentBucket());
}
public static void main(String[] args) throws Exception {
Options opt = new OptionsBuilder()
.include(RollingNumberBenchmark.class.getSimpleName())
.forks(1)
.build();
new Runner(opt).run();
}
}