Skip to content

Commit 707e0c0

Browse files
Add ParallelFormatBenchmark for testing multi-iteration parser structure formatting performance
1 parent bc2a745 commit 707e0c0

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.alternativeParsing
11+
import kotlinx.datetime.format.char
12+
import org.openjdk.jmh.annotations.*
13+
import org.openjdk.jmh.infra.Blackhole
14+
import java.util.concurrent.TimeUnit
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 ParallelFormatBenchmark {
23+
24+
@Param("2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")
25+
var n = 0
26+
27+
@Benchmark
28+
fun foo(blackhole: Blackhole) {
29+
val format = LocalDateTime.Format {
30+
repeat(n) {
31+
alternativeParsing(
32+
{ monthNumber() },
33+
{ day() },
34+
primaryFormat = { hour() }
35+
)
36+
char('@')
37+
minute()
38+
char('#')
39+
second()
40+
}
41+
}
42+
blackhole.consume(format)
43+
}
44+
}

0 commit comments

Comments
 (0)