From 550ae2215c016fcf795026467147b4caaea26ae4 Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 23 Mar 2022 19:29:44 +0100 Subject: [PATCH] add jmh --- build.gradle | 20 +++++++++++++++++++ .../ititus/commons/lexer/LexerBenchmark.java | 19 ++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/jmh/java/io/github/ititus/commons/lexer/LexerBenchmark.java diff --git a/build.gradle b/build.gradle index 1888882..bb6af85 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ import java.time.Duration plugins { id 'java-library' + id 'me.champeau.jmh' version '0.6.6' id 'maven-publish' id 'signing' id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' @@ -23,6 +24,14 @@ java { withJavadocJar() } +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +tasks.withType(Test) { + systemProperty 'file.encoding', 'UTF-8' +} + javadoc { options { addStringOption('Xdoclint:all,-missing', '-quiet') @@ -44,6 +53,17 @@ test { useJUnitPlatform() } +jmh { + jmhVersion = '1.34' + warmupIterations = 2 + iterations = 5 + fork = 1 +} + +tasks.withType(me.champeau.jmh.JmhParameters) { + jvmArgsAppend = ['-Dfile.encoding=UTF-8'] +} + publishing { publications { MyPublication(MavenPublication) { diff --git a/src/jmh/java/io/github/ititus/commons/lexer/LexerBenchmark.java b/src/jmh/java/io/github/ititus/commons/lexer/LexerBenchmark.java new file mode 100644 index 0000000..97f4fda --- /dev/null +++ b/src/jmh/java/io/github/ititus/commons/lexer/LexerBenchmark.java @@ -0,0 +1,19 @@ +package io.github.ititus.commons.lexer; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.infra.Blackhole; + +@State(Scope.Benchmark) +public class LexerBenchmark { + + @Benchmark + public void add(Blackhole bh) { + int a = 1; + int b = 2; + int sum = a + b; + + bh.consume(sum); + } +}