From b083aab0db52f0a9ecbdbdbeaff1b9cf6f0a9934 Mon Sep 17 00:00:00 2001 From: Daniel Lin Date: Thu, 26 Dec 2024 03:29:11 -0500 Subject: [PATCH] Better sort day 17 benchmarks --- kt/aoc2024-exe/build.gradle.kts | 6 ++ .../ephemient/aoc2024/exe/Day17Bench.kt | 77 +++++++++++++++++++ .../ephemient/aoc2024/exe/Day17JvmBench.kt | 45 ----------- .../ephemient/aoc2024/exe/Day17Bench.kt | 0 kt/graalvm/build.gradle.kts | 10 ++- 5 files changed, 89 insertions(+), 49 deletions(-) create mode 100644 kt/aoc2024-exe/src/jvmBench/kotlin/com/github/ephemient/aoc2024/exe/Day17Bench.kt delete mode 100644 kt/aoc2024-exe/src/jvmBench/kotlin/com/github/ephemient/aoc2024/exe/Day17JvmBench.kt rename kt/aoc2024-exe/src/{commonBench => nonJvmBench}/kotlin/com/github/ephemient/aoc2024/exe/Day17Bench.kt (100%) diff --git a/kt/aoc2024-exe/build.gradle.kts b/kt/aoc2024-exe/build.gradle.kts index 82df080e..276dc8aa 100644 --- a/kt/aoc2024-exe/build.gradle.kts +++ b/kt/aoc2024-exe/build.gradle.kts @@ -71,6 +71,12 @@ kotlin { group("nonblocking") { withWasmJs() } + group("nonJvm") { + group("native") { + withNative() + } + withWasmJs() + } } } diff --git a/kt/aoc2024-exe/src/jvmBench/kotlin/com/github/ephemient/aoc2024/exe/Day17Bench.kt b/kt/aoc2024-exe/src/jvmBench/kotlin/com/github/ephemient/aoc2024/exe/Day17Bench.kt new file mode 100644 index 00000000..7b471c83 --- /dev/null +++ b/kt/aoc2024-exe/src/jvmBench/kotlin/com/github/ephemient/aoc2024/exe/Day17Bench.kt @@ -0,0 +1,77 @@ +package com.github.ephemient.aoc2024.exe + +import com.github.ephemient.aoc2024.Day17 +import com.github.ephemient.aoc2024.Day17Jvm +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.Blackhole +import kotlinx.benchmark.Scope +import kotlinx.benchmark.Setup +import kotlinx.benchmark.State + +@State(Scope.Benchmark) +class Day17Bench { + private lateinit var input: String + private lateinit var day17: Day17 + private var day17Jvm: Day17Jvm? = null + + @Setup + fun setup() { + input = getDayInput(17) + day17 = Day17(input) + day17Jvm = try { + Day17Jvm(input) + } catch (_: AssertionError) { + null + } + } + + @Benchmark + fun part1() = Day17(input).part1() + + @Benchmark + fun part1_cached() = day17.part1() + + @Benchmark + fun part1_jvm() = Day17Jvm(input).part1() + + @Benchmark + fun part1_jvm_cached() = day17Jvm!!.part1() + + @Benchmark + fun part2() = Day17(input).part2() + + @Benchmark + fun part2_cached() = day17.part2() + + @Benchmark + fun part2_jvm() = Day17Jvm(input).part2() + + @Benchmark + fun part2_jvm_cached() = day17Jvm!!.part2() + + @Benchmark + fun solve(bh: Blackhole) { + val day17 = Day17(input) + bh.consume(day17.part1()) + bh.consume(day17.part2()) + } + + @Benchmark + fun solve_cached(bh: Blackhole) { + bh.consume(day17.part1()) + bh.consume(day17.part2()) + } + + @Benchmark + fun solve_jvm(bh: Blackhole) { + val day17Jvm = Day17Jvm(input) + bh.consume(day17Jvm.part1()) + bh.consume(day17Jvm.part2()) + } + + @Benchmark + fun solve_jvm_cached(bh: Blackhole) { + bh.consume(day17Jvm!!.part1()) + bh.consume(day17Jvm!!.part2()) + } +} diff --git a/kt/aoc2024-exe/src/jvmBench/kotlin/com/github/ephemient/aoc2024/exe/Day17JvmBench.kt b/kt/aoc2024-exe/src/jvmBench/kotlin/com/github/ephemient/aoc2024/exe/Day17JvmBench.kt deleted file mode 100644 index 4e059d38..00000000 --- a/kt/aoc2024-exe/src/jvmBench/kotlin/com/github/ephemient/aoc2024/exe/Day17JvmBench.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.ephemient.aoc2024.exe - -import com.github.ephemient.aoc2024.Day17Jvm -import kotlinx.benchmark.Benchmark -import kotlinx.benchmark.Blackhole -import kotlinx.benchmark.Scope -import kotlinx.benchmark.Setup -import kotlinx.benchmark.State - -@State(Scope.Benchmark) -class Day17JvmBench { - private lateinit var input: String - private lateinit var day17: Day17Jvm - - @Setup - fun setup() { - input = getDayInput(17) - day17 = Day17Jvm(input) - } - - @Benchmark - fun part1() = Day17Jvm(input).part1() - - @Benchmark - fun part1_cached() = day17.part1() - - @Benchmark - fun part2() = Day17Jvm(input).part2() - - @Benchmark - fun part2_cached() = day17.part2() - - @Benchmark - fun solve(bh: Blackhole) { - val day17 = Day17Jvm(input) - bh.consume(day17.part1()) - bh.consume(day17.part2()) - } - - @Benchmark - fun solve_cached(bh: Blackhole) { - bh.consume(day17.part1()) - bh.consume(day17.part2()) - } -} diff --git a/kt/aoc2024-exe/src/commonBench/kotlin/com/github/ephemient/aoc2024/exe/Day17Bench.kt b/kt/aoc2024-exe/src/nonJvmBench/kotlin/com/github/ephemient/aoc2024/exe/Day17Bench.kt similarity index 100% rename from kt/aoc2024-exe/src/commonBench/kotlin/com/github/ephemient/aoc2024/exe/Day17Bench.kt rename to kt/aoc2024-exe/src/nonJvmBench/kotlin/com/github/ephemient/aoc2024/exe/Day17Bench.kt diff --git a/kt/graalvm/build.gradle.kts b/kt/graalvm/build.gradle.kts index 0ec80511..2a438a2f 100644 --- a/kt/graalvm/build.gradle.kts +++ b/kt/graalvm/build.gradle.kts @@ -23,7 +23,9 @@ val benchmarkRun by tasks.registering(JavaExec::class) { mainClass = "org.openjdk.jmh.Main" classpath(benchmark.output, benchmark.runtimeClasspath) args("-f", 0, "-wi", 1, "-w", "0s", "-r", "0s", "-bm", "avgt", "-tu", "us", "-i", 1) - args("-rf", "json", "-rff", "/dev/null") + args("-rf", "json", "-rff", "/dev/null", "-e", "jvm") + project.findProperty("benchmarkExclude")?.let { args("-e", it) } + project.findProperty("benchmarkInclude")?.let { args(it) } outputs.dir(AgentConfigurationFactory.getAgentOutputDirectoryForTask(layout, name)) } val syncBenchmarkRunMetadata by tasks.registering(Sync::class) { @@ -43,9 +45,9 @@ graalvmNative { classpath(syncBenchmarkRunMetadata, benchmark.output, benchmark.runtimeClasspath) runtimeArgs("-f", 0, "-wi", 1, "-w", "1s", "-r", "1s", "-bm", "avgt", "-tu", "us") val benchmarkFile = benchmarkDir.get().file("graalvmBench.json") - runtimeArgs("-rf", "json", "-rff", benchmarkFile.asFile) - findProperty("benchmarkExclude")?.let { runtimeArgs("-e", it) } - findProperty("benchmarkInclude")?.let { runtimeArgs(it) } + runtimeArgs("-rf", "json", "-rff", benchmarkFile.asFile, "-e", "jvm") + project.findProperty("benchmarkExclude")?.let { runtimeArgs("-e", it) } + project.findProperty("benchmarkInclude")?.let { runtimeArgs(it) } } } agent {