Skip to content

Instantly share code, notes, and snippets.

@eleco
Created April 16, 2015 19:23
Show Gist options
  • Save eleco/4f7fe0b042efdd88fe95 to your computer and use it in GitHub Desktop.
Save eleco/4f7fe0b042efdd88fe95 to your computer and use it in GitHub Desktop.
Simple Servo benchmark test
package jmh;
import com.netflix.servo.monitor.Counter;
import com.netflix.servo.monitor.MaxGauge;
import com.netflix.servo.monitor.MonitorConfig;
import com.netflix.servo.monitor.Monitors;
import org.openjdk.jmh.annotations.*;
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.Thread)
public class MyBenchmark {
private Counter counter;
private MaxGauge gauge;
private int testValue = 0;
@Param({"true", "false"})
private boolean register = false;
@Setup
public void setup() {
gauge = new MaxGauge(MonitorConfig.builder("gauge").build());
counter = Monitors.newCounter("counter");
if (register) {
Monitors.registerObject("mycounter", counter);
Monitors.registerObject("mygauge", gauge);
}
}
@Benchmark
public void simpleServoCounterTest() {
counter.increment();
}
@Benchmark
public void simpleServoGaugeTest() {
gauge.update(testValue++);
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(MyBenchmark.class.getSimpleName())
.warmupIterations(5)
.measurementIterations(5)
.forks(1)
.build();
new Runner(opt).run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment