diff --git a/README.md b/README.md index e81cd12..023dc9d 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ This should include version >= 23, e.g.: ### Development Setup with nix -The provided [shell.nix](shell.nix) file can be used to set up a development environment with IntelliJ. The only prerequisite is to have a working `nix` installation for which there are multiple possibilities, e.g: +The provided [./shell.nix](./shell.nix) file can be used to set up a development environment with IntelliJ. The only prerequisite is to have a working `nix` installation for which there are multiple possibilities, e.g: ```shell # https://github.com/DeterminateSystems/nix-installer?tab=readme-ov-file#determinate-nix-installer @@ -90,26 +90,37 @@ There are two different benchmarks. One is based on the JMH benchmark framework, ### Custom -Run custom benchmark: +Run Custom Benchmark (CGM) with + +- Custom Generated Lists (CGL): ```shell ./gradlew runCbmCgl +``` + +- Powersort competition lists: + +```shell ./gradlew runCbmCompetition ``` ### JMH -Run JMH benchmark: +#### Run JMH with CGL and Powersort competition lists ```shell ./gradlew jmh ``` -IntelliJ plugin: +- To benchmark only one of the different list collections, see `jmh { excludes }` at the bottom of [./app/build.gradle.kts](./app/build.gradle.kts). + +#### IntelliJ plugin The [JMH Java Microbenchmark Harness](https://plugins.jetbrains.com/plugin/7529-jmh-java-microbenchmark-harness) plugin allows running benchmarks from within the IDE in a similar way as JUnit test cases. This can be used for development but yields less accurate results. -Further notes: +![intellij-jmh.png](intellij-jmh.png) + +#### Further notes - JHM: https://github.com/openjdk/jmh?tab=readme-ov-file#other-build-systems - We use the JMH Gradle plugin: https://github.com/melix/jmh-gradle-plugin diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1628776..6aadce9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -83,6 +83,8 @@ jmh { forceGC = true excludes = listOf( - "de.uni_marburg.powersort.benchmark.JmhBase.benchmark", + // To skip JmhCgl or JmhCompetition, uncomment it below. +// "de.uni_marburg.powersort.benchmark.JmhCgl.benchmark", +// "de.uni_marburg.powersort.benchmark.JmhCompetition.benchmark", ) } diff --git a/app/src/jmh/java/de/uni_marburg/powersort/benchmark/JmhBase.java b/app/src/jmh/java/de/uni_marburg/powersort/benchmark/JmhBase.java index 237af37..f8b3e81 100644 --- a/app/src/jmh/java/de/uni_marburg/powersort/benchmark/JmhBase.java +++ b/app/src/jmh/java/de/uni_marburg/powersort/benchmark/JmhBase.java @@ -4,7 +4,6 @@ import de.uni_marburg.powersort.data.DataEnum; import de.uni_marburg.powersort.data.ObjectSupplier; import de.uni_marburg.powersort.sort.SortEnum; import de.uni_marburg.powersort.sort.SortImpl; -import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Level; @@ -75,9 +74,4 @@ public class JmhBase { // This way, all iterations sort the same input. workingCopy = data.getCopy(); } - - @Benchmark - public void benchmark() { - sortImpl.sort(workingCopy); - } } diff --git a/app/src/jmh/java/de/uni_marburg/powersort/benchmark/JmhCgl.java b/app/src/jmh/java/de/uni_marburg/powersort/benchmark/JmhCgl.java index ede8f4a..96d2355 100644 --- a/app/src/jmh/java/de/uni_marburg/powersort/benchmark/JmhCgl.java +++ b/app/src/jmh/java/de/uni_marburg/powersort/benchmark/JmhCgl.java @@ -3,6 +3,7 @@ package de.uni_marburg.powersort.benchmark; import de.uni_marburg.powersort.data.CglEnum; import de.uni_marburg.powersort.data.DataEnum; import de.uni_marburg.powersort.sort.SortEnum; +import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Param; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; @@ -28,4 +29,12 @@ public class JmhCgl extends JmhBase { SortEnum getSortEnum(){ return sortEnum; } + + // We could move this method up to JmhBase to avoid redundancy in the subclasses. + // But this would remove the run button of the IntelliJ plugin "JMH Java Microbenchmark Harness". + // Furthermore, with this approach we don't need to exclude JmhBase as it has no benchmark methods. + @Benchmark + public void benchmark() { + sortImpl.sort(workingCopy); + } } diff --git a/app/src/jmh/java/de/uni_marburg/powersort/benchmark/JmhCompetition.java b/app/src/jmh/java/de/uni_marburg/powersort/benchmark/JmhCompetition.java index f6b4cba..8d77a10 100644 --- a/app/src/jmh/java/de/uni_marburg/powersort/benchmark/JmhCompetition.java +++ b/app/src/jmh/java/de/uni_marburg/powersort/benchmark/JmhCompetition.java @@ -3,6 +3,7 @@ package de.uni_marburg.powersort.benchmark; import de.uni_marburg.powersort.data.CompetitionEnum; import de.uni_marburg.powersort.data.DataEnum; import de.uni_marburg.powersort.sort.SortEnum; +import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Param; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; @@ -28,4 +29,9 @@ public class JmhCompetition extends JmhBase { SortEnum getSortEnum(){ return sortEnum; } + + @Benchmark + public void benchmark() { + sortImpl.sort(workingCopy); + } } diff --git a/intellij-jmh.png b/intellij-jmh.png new file mode 100644 index 0000000..68ffbf4 Binary files /dev/null and b/intellij-jmh.png differ