Skip to content

Commit d8fae29

Browse files
Add JMH benchmark for parser structure formatting
1 parent 4f8a1e1 commit d8fae29

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2019-2025 JetBrains s.r.o. and contributors.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
@file:Suppress("unused")
7+
8+
package kotlinx.datetime
9+
10+
import kotlinx.datetime.format.char
11+
import kotlinx.datetime.format.optional
12+
import org.openjdk.jmh.annotations.*
13+
import org.openjdk.jmh.infra.Blackhole
14+
import java.util.concurrent.*
15+
16+
@Warmup(iterations = 5, time = 1)
17+
@Measurement(iterations = 5, time = 1)
18+
@BenchmarkMode(Mode.AverageTime)
19+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
20+
@State(Scope.Benchmark)
21+
@Fork(1)
22+
open class ParserStructureConcatBenchmark {
23+
24+
@Benchmark
25+
fun buildFormat(blackhole: Blackhole) {
26+
val v = LocalDateTime.Format {
27+
year()
28+
char('-')
29+
monthNumber()
30+
char('-')
31+
day()
32+
char(' ')
33+
hour()
34+
char(':')
35+
minute()
36+
optional {
37+
char(':')
38+
second()
39+
optional {
40+
char('.')
41+
secondFraction()
42+
}
43+
}
44+
}
45+
blackhole.consume(v)
46+
}
47+
}

0 commit comments

Comments
 (0)