Rudziankoŭ
Rudziankoŭ

Reputation: 11251

Basic understanding of JMH Benchmark

I have such spring class:

@Component
@State(Scope.Thread)
public class CalculatorImpl implements Calculator {

    public CalculatorImpl() {
        System.out.println("Phase 1");
    }

    @PostConstruct
    @Benchmark
    public void init() {
        System.out.println("Phase 2");
    }
}

I added required maven dependencies and plugin and run it with:

java -jar target/benchmarks.jar

And my "Phase 2" printing goes to infinite loop. Basically, I just want helloworld example. What have I done wrong? Thanks for your time.

Upvotes: 0

Views: 601

Answers (1)

qwazer
qwazer

Reputation: 7531

See hello world example here http://hg.openjdk.java.net/code-tools/jmh/file/7a25c71b43bf/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_01_HelloWorld.java

I suppose, that in you case you got not infinite loop but very long invocation possibly limited or timeouted by speed of print line on your terminal. Try to benchmark empty method first.

Upvotes: 1

Related Questions