Reputation: 211
I've created a class. Within that class I have several methods that are marked as @Benchmark
. I also have a main method that runs the JMH benchmarks:
System.out.println("NUMBER OF THREADS: "+numOfThreads);
Options opt = new OptionsBuilder()
.include(JMHtopToBottom.class.getSimpleName())
.warmupIterations(5)
.measurementIterations(3)
.forks(numOfThreads)
.build();
Collection<RunResult> collection = new Runner(opt).run();
My interest is to have:
A setup method that runs only ones - right after the new Runner(opt).run();
and before all of the @Benchmark
methods are called (along with their iterations).
As well, to have a tear down method that runs only once right after all the methods runs and before we go back to main.
When I tried @setup
and @tear_down
(with Level
support: Trial
/Iteration
/Invocation
) the methods run several times and not only ones as I wished. Is there a way in JMH to annotate methods so it will run just ones - right after run()
and right before the run()
is over?
Upvotes: 1
Views: 3043
Reputation: 2909
You are missing a few things:
If you absolutely require some 'Suite' level context you'll have to construct it out of VM (e.g. some file that is read on benchmark setup/updated on teardown etc.).
Upvotes: 5