Skip to content

Commit 0ee4b0d

Browse files
authored
Demo benchmark. (#2)
1 parent c5973e4 commit 0ee4b0d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

build.gradle.kts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import kotlinx.benchmark.gradle.JvmBenchmarkTarget
12
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23

34
plugins {
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

1315
dependencies {
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+
2936
detekt {
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+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

0 commit comments

Comments
 (0)