File tree Expand file tree Collapse file tree 2 files changed +52
-1
lines changed
src/main/kotlin/io/dmitrijs/aoc2022 Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 1+ import kotlinx.benchmark.gradle.JvmBenchmarkTarget
12import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23
34plugins {
45 kotlin(" jvm" ) version " 1.7.22"
5- id(" org.jetbrains.kotlinx.benchmark" ) version " 0.4.6"
6+ kotlin(" plugin.allopen" ) version " 1.7.22"
7+ id(" org.jetbrains.kotlinx.benchmark" ) version " 0.4.7"
68 id(" io.gitlab.arturbosch.detekt" ) version " 1.22.0"
79}
810
@@ -11,6 +13,7 @@ repositories {
1113}
1214
1315dependencies {
16+ implementation(" org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.7" )
1417 testImplementation(kotlin(" test" ))
1518 detektPlugins(" io.gitlab.arturbosch.detekt:detekt-formatting:1.22.0" )
1619}
@@ -26,7 +29,26 @@ tasks {
2629 }
2730}
2831
32+ allOpen {
33+ annotation(" org.openjdk.jmh.annotations.State" )
34+ }
35+
2936detekt {
3037 config = files(" detekt-config.yml" )
3138 buildUponDefaultConfig = true
3239}
40+
41+ benchmark {
42+ configurations {
43+ named(" main" ) {
44+ iterationTime = 5
45+ iterationTimeUnit = " sec"
46+ }
47+ }
48+ targets {
49+ register(" main" ) {
50+ this as JvmBenchmarkTarget
51+ jmhVersion = " 1.36"
52+ }
53+ }
54+ }
Original file line number Diff line number Diff line change 1+ package io.dmitrijs.aoc2022
2+
3+ import io.dmitrijs.aoc2022.Resources.resourceAsLines
4+ import kotlinx.benchmark.Benchmark
5+ import kotlinx.benchmark.Measurement
6+ import kotlinx.benchmark.Scope
7+ import kotlinx.benchmark.Setup
8+ import kotlinx.benchmark.State
9+ import kotlinx.benchmark.Warmup
10+ import org.openjdk.jmh.annotations.Fork
11+
12+ @State(Scope .Benchmark )
13+ @Warmup(iterations = 1 )
14+ @Measurement(iterations = 4 )
15+ @Fork(1 )
16+ class Day10Benchmark {
17+ private lateinit var input: List <String >
18+
19+ @Setup
20+ fun setUp () {
21+ input = resourceAsLines(" day10" )
22+ }
23+
24+ @Benchmark
25+ fun puzzle1 () = Day10 (input).puzzle1()
26+
27+ @Benchmark
28+ fun puzzle2 () = Day10 (input).puzzle2()
29+ }
You can’t perform that action at this time.
0 commit comments