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

Commit

Permalink
Allow to configure benchmark from CLI (#1663)
Browse files Browse the repository at this point in the history
* Allow to configure benchmark

* add threads
  • Loading branch information
Gal Rogozinski authored Dec 2, 2019
1 parent 24beafc commit 80b7834
Showing 1 changed file with 37 additions and 13 deletions.
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));
}
}

0 comments on commit 80b7834

Please sign in to comment.