Created
April 16, 2015 19:23
-
-
Save eleco/4f7fe0b042efdd88fe95 to your computer and use it in GitHub Desktop.
Simple Servo benchmark test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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