Skip to content

Commit 9681c6e

Browse files
Add formatCreationWithNestedAlternativeParsing benchmark to test complex parser structures
1 parent 792ed80 commit 9681c6e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

benchmarks/src/jmh/kotlin/ParallelFormatBenchmark.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,48 @@ open class ParallelFormatBenchmark {
4141
}
4242
blackhole.consume(format)
4343
}
44+
45+
@Benchmark
46+
fun formatCreationWithNestedAlternativeParsing(blackhole: Blackhole) {
47+
val format = LocalDateTime.Format {
48+
repeat(n) { index ->
49+
alternativeParsing(
50+
{ monthNumber(); char('-'); day() },
51+
{ day(); char('/'); monthNumber() },
52+
primaryFormat = { year(); char('-'); monthNumber(); char('-'); day() }
53+
)
54+
55+
if (index % 2 == 0) {
56+
alternativeParsing(
57+
{
58+
alternativeParsing(
59+
{ hour(); char(':'); minute() },
60+
{ minute(); char(':'); second() },
61+
primaryFormat = { hour(); char(':'); minute(); char(':'); second() }
62+
)
63+
},
64+
primaryFormat = {
65+
year(); char('-'); monthNumber(); char('-'); day()
66+
char('T')
67+
hour(); char(':'); minute(); char(':'); second()
68+
}
69+
)
70+
}
71+
72+
char('|')
73+
if (index % 3 == 0) {
74+
char('|')
75+
}
76+
77+
if (index < 8) {
78+
alternativeParsing(
79+
{ char('Z') },
80+
{ char('+'); hour(); char(':'); minute() },
81+
primaryFormat = { char('-'); hour(); char(':'); minute() }
82+
)
83+
}
84+
}
85+
}
86+
blackhole.consume(format)
87+
}
4488
}

0 commit comments

Comments
 (0)