Skip to content

Commit 0f5f901

Browse files
Add SerialFormatBenchmark for evaluating large format serialization performance
1 parent 40b8dd3 commit 0f5f901

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 org.openjdk.jmh.annotations.*
12+
import org.openjdk.jmh.infra.Blackhole
13+
import java.util.concurrent.TimeUnit
14+
15+
@Warmup(iterations = 10, time = 2)
16+
@Measurement(iterations = 20, time = 2)
17+
@BenchmarkMode(Mode.AverageTime)
18+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
19+
@State(Scope.Benchmark)
20+
@Fork(1)
21+
open class SerialFormatBenchmark {
22+
23+
@Param("1", "2", "4", "8", "16", "32", "64", "128", "256", "512", "1024")
24+
var n = 0
25+
26+
@Benchmark
27+
fun largeSerialFormat(blackhole: Blackhole) {
28+
val format = LocalDateTime.Format {
29+
repeat(n) {
30+
char('^')
31+
monthNumber()
32+
char('&')
33+
day()
34+
char('!')
35+
hour()
36+
char('$')
37+
minute()
38+
char('#')
39+
second()
40+
char('@')
41+
}
42+
}
43+
blackhole.consume(format)
44+
}
45+
}

0 commit comments

Comments
 (0)