Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Allow to configure benchmark from CLI #1663

Merged
merged 2 commits into from
Dec 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions src/test/java/com/iota/iri/benchmarks/BenchmarkRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.Optional;
import java.util.concurrent.TimeUnit;

public class BenchmarkRunner {

@Test
public void launchDbBenchmarks() throws RunnerException {

Options opts = new OptionsBuilder()
.include(RocksDbBenchmark.class.getName() + ".*")
.mode(Mode.AverageTime)
.timeUnit(TimeUnit.MILLISECONDS)
.warmupIterations(5)
.forks(1)
.measurementIterations(10)
.warmupIterations(getWarmUpIterations(5))
.forks(getForks(1))
.threads(getThreads())
.measurementIterations(getMeasurementIterations(10))
.shouldFailOnError(true)
.shouldDoGC(false)
.build();
Expand All @@ -32,15 +35,36 @@ public void launchDbBenchmarks() throws RunnerException {
@Test
public void launchCryptoBenchmark() throws RunnerException {
Options opts = new OptionsBuilder()
.include(this.getClass().getPackage().getName() + ".crypto")
.mode(Mode.Throughput)
.timeUnit(TimeUnit.SECONDS)
.warmupIterations(5)
.forks(1)
.measurementIterations(10)
.shouldFailOnError(true)
.shouldDoGC(false)
.build();
.include(this.getClass().getPackage().getName() + ".crypto")
.mode(Mode.Throughput)
.timeUnit(TimeUnit.SECONDS)
.warmupIterations(getWarmUpIterations(5))
.forks(getForks(1))
.threads(getThreads())
.measurementIterations(getMeasurementIterations(10))
.shouldFailOnError(true)
.shouldDoGC(false)
.build();
new Runner(opts).run();
}
}

private int getThreads() {
return getProperty("threads", Integer.toString(Runtime.getRuntime().availableProcessors()));
}

private int getForks(int defValue) {
return getProperty("forks", Integer.toString(defValue));
}

private int getWarmUpIterations(int defValue) {
return getProperty("warmUpIterations", Integer.toString(defValue));
}

private int getMeasurementIterations(int defValue) {
return getProperty("measurementIterations", Integer.toString(defValue));
}

private int getProperty(String property, String defValue){
return Integer.valueOf(Optional.ofNullable(System.getProperty(property)).orElse(defValue));
}
}