src/perf/java/com/github/cukedoctor/CukedoctorBenchmark
@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
public class CukedoctorBenchmark {
private static CukedoctorConverter cukedoctorConverter;
private static List<Feature> asciidoctorFeatures;
private static Asciidoctor asciidoctor;
@State(Scope.Thread)
public static class BenchmarkContext {
@Setup
public void init() throws RunnerException {
Logger.getLogger(FileUtil.class.getName()).setLevel(Level.SEVERE);
String asciidoctorFeaturesPath = FileUtil.findJsonFile(Thread.currentThread().getContextClassLoader().getResource("asciidoctor-features.json").getPath());
asciidoctorFeatures = FeatureParser.parse(asciidoctorFeaturesPath);
cukedoctorConverter = Cukedoctor.instance(asciidoctorFeatures);
}
}
@Benchmark
public void convert(BenchmarkContext ctx) {
String livingDocumentation = cukedoctorConverter.renderDocumentation();
File adocFile = FileUtil.saveFile("target/benchmark/" + UUID.randomUUID().toString() + ".adoc", livingDocumentation);
//Asciidoctor.Factory.create().convertFile(adocFile, org.asciidoctor.OptionsBuilder.options().backend("html").safe(SafeMode.UNSAFE).asMap());
}
public static void main(String[] args) throws RunnerException, InterruptedException {
try {
new Runner(new OptionsBuilder().
forks(3).
threads(8).
warmupIterations(5).
warmupForks(1).
measurementIterations(10).
include(CukedoctorBenchmark.class.getSimpleName()).
measurementTime(TimeValue.milliseconds(350)).
build()
).run();
}finally { (1)
List<String> files = FileUtil.findFiles("target/benchmark", new String[]{"**/*.adoc"});
Logger.getLogger(CukedoctorBenchmark.class.getName()).info("Number of files converted: " + files.size());
CukedoctorBenchmark.removeAdocFIles();
}
}
private static void removeAdocFIles() {
List<String> files = FileUtil.findFiles("target/benchmark", new String[]{"**/*.adoc"});
if (files != null) {
for (String file : files) {
FileUtil.removeFile(file);
}
}
}
}
-
@TearDown will not help cause its called per iteration
pom.xml
<profile>
<id>perf</id>
<build>
<resources>
<resource>
<directory>src/perf/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerVersion>1.7</compilerVersion>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.github.cukedoctor.CukedoctorBenchmark</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/perf/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
travis.yml
sudo: false language: java jdk: oraclejdk8 cache: directories: - '$HOME/.m2/repository' script: - mvn compile exec:exec -Pperf