Created
December 29, 2016 19:26
-
-
Save mike-ensor/849857258283b3b91bdb25761b9d7fa2 to your computer and use it in GitHub Desktop.
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
@SpringBootApplication | |
public class BenchmarkBase { | |
public static void main(String[] args) throws RunnerException, IOException { | |
Properties properties = PropertiesLoaderUtils.loadAllProperties("benchmark.properties"); | |
int warmup = Integer.parseInt(properties.getProperty("benchmark.warmup.iterations", "5")); | |
int iterations = Integer.parseInt(properties.getProperty("benchmark.test.iterations", "5")); | |
int forks = Integer.parseInt(properties.getProperty("benchmark.test.forks", "1")); | |
int threads = Integer.parseInt(properties.getProperty("benchmark.test.threads", "1")); | |
String testClassRegExPattern = properties.getProperty("benchmark.global.testclassregexpattern", ".*Benchmark.*"); | |
String resultFilePrefix = properties.getProperty("benchmark.global.resultfileprefix", "jmh-"); | |
ResultFormatType resultsFileOutputType = ResultFormatType.JSON; | |
Options opt = new OptionsBuilder() | |
.include(testClassRegExPattern) | |
.warmupIterations(warmup) | |
.measurementIterations(iterations) | |
.forks(forks) | |
.threads(threads) | |
.shouldDoGC(true) | |
.shouldFailOnError(true) | |
.resultFormat(resultsFileOutputType) | |
.result(buildResultsFileName(resultFilePrefix, resultsFileOutputType)) | |
.shouldFailOnError(true) | |
.jvmArgs("-server") | |
.build(); | |
new Runner(opt).run(); | |
} | |
private static String buildResultsFileName(String resultFilePrefix, ResultFormatType resultType) { | |
LocalDateTime date = LocalDateTime.now(); | |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("mm-dd-yyyy-hh-mm-ss"); | |
String suffix; | |
switch (resultType) { | |
case CSV: | |
suffix = ".csv"; | |
break; | |
case SCSV: | |
// Semi-colon separated values | |
suffix = ".scsv"; | |
break; | |
case LATEX: | |
suffix = ".tex"; | |
break; | |
case JSON: | |
default: | |
suffix = ".json"; | |
break; | |
} | |
return String.format("target/%s%s%s", resultFilePrefix, date.format(formatter), suffix); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment