Skip to content

Commit ee2202c

Browse files
authored
JMH tests (#4)
1 parent 48d2192 commit ee2202c

File tree

3 files changed

+7621
-0
lines changed

3 files changed

+7621
-0
lines changed

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ plugins {
33
id "com.exactpro.th2.gradle.component" version "0.1.1"
44
id "org.jetbrains.kotlin.jvm" version "$kotlin_version"
55
id "org.jetbrains.kotlin.kapt" version "$kotlin_version"
6+
id "me.champeau.jmh" version "0.7.2"
67
}
78

89
ext {
910
sailfishVersion = '3.3.241'
1011
commonVersion = '5.14.0-dev'
12+
jmhVersion = '1.37'
1113
}
1214

1315
group = 'com.exactpro.th2'
@@ -89,6 +91,10 @@ dependencies {
8991
annotationProcessor "com.google.auto.service:auto-service:1.1.1"
9092
kapt "com.google.auto.service:auto-service:1.1.1"
9193

94+
jmh "org.openjdk.jmh:jmh-core:$jmhVersion"
95+
jmh "org.openjdk.jmh:jmh-generator-annprocess:$jmhVersion"
96+
jmh "org.openjdk.jmh:jmh-generator-bytecode:$jmhVersion"
97+
9298
testImplementation "org.junit.jupiter:junit-jupiter"
9399
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
94100
testImplementation "org.assertj:assertj-core:3.26.3"
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Copyright 2024 Exactpro (Exactpro Systems Limited)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.exactpro.th2.codec.fixng
18+
19+
import com.exactpro.sf.common.messages.structures.IDictionaryStructure
20+
import com.exactpro.sf.common.messages.structures.loaders.XmlDictionaryStructureLoader
21+
import com.exactpro.th2.codec.api.IPipelineCodec
22+
import com.exactpro.th2.codec.api.IReportingContext
23+
import com.exactpro.th2.codec.fixng.FixNgCodecFactory.Companion.PROTOCOL
24+
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.Direction
25+
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.EventId
26+
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.MessageGroup
27+
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.MessageId
28+
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.ParsedMessage
29+
import com.exactpro.th2.common.schema.message.impl.rabbitmq.transport.RawMessage
30+
import io.netty.buffer.ByteBuf
31+
import io.netty.buffer.Unpooled
32+
import org.openjdk.jmh.annotations.Benchmark
33+
import org.openjdk.jmh.annotations.BenchmarkMode
34+
import org.openjdk.jmh.annotations.Level
35+
import org.openjdk.jmh.annotations.Mode
36+
import org.openjdk.jmh.annotations.Scope
37+
import org.openjdk.jmh.annotations.Setup
38+
import org.openjdk.jmh.annotations.State
39+
import java.time.Instant
40+
41+
@State(Scope.Benchmark)
42+
open class BenchmarkState {
43+
lateinit var codec: IPipelineCodec
44+
lateinit var rawBody: ByteBuf
45+
lateinit var rawGroup: MessageGroup
46+
lateinit var parsedGroup: MessageGroup
47+
48+
@Setup(Level.Trial)
49+
fun setup() {
50+
val dictionary: IDictionaryStructure = FixNgCodecTest::class.java.classLoader
51+
.getResourceAsStream("dictionary-benchmark.xml")
52+
.use(XmlDictionaryStructureLoader()::load)
53+
54+
codec = FixNgCodec(dictionary, FixNgCodecSettings(dictionary = "", decodeValuesToStrings = true))
55+
rawBody = Unpooled.wrappedBuffer(MSG_CORRECT.toByteArray(Charsets.US_ASCII))
56+
rawGroup = MessageGroup(listOf(RawMessage(id = parsedMessage.id, eventId = parsedMessage.eventId, body = rawBody)))
57+
parsedGroup = MessageGroup(listOf(parsedMessage))
58+
}
59+
60+
@Setup(Level.Invocation)
61+
fun resetReader() {
62+
rawBody.resetReaderIndex()
63+
}
64+
65+
companion object {
66+
private const val MSG_CORRECT = "8=FIXT.1.1\u00019=295\u000135=8\u000149=SENDER\u000156=RECEIVER\u000134=10947\u000152=20230419-10:36:07.415088\u000117=495504662\u000111=zSuNbrBIZyVljs\u000141=zSuNbrBIZyVljs\u000137=49415882\u0001150=0\u000139=0\u0001151=500\u000114=500\u000148=NWDR\u000122=8\u0001453=2\u0001448=NGALL1FX01\u0001447=D\u0001452=76\u0001448=0\u0001447=P\u0001452=3\u00011=test\u000140=A\u000159=0\u000154=B\u000155=ABC\u000138=500\u000144=1000\u000147=500\u000160=20180205-10:38:08.000008\u000110=191\u0001"
67+
private val parsedMessage = ParsedMessage(
68+
MessageId("test_alias", Direction.OUTGOING, 0L, Instant.now(), emptyList()),
69+
EventId("test_id", "test_book", "test_scope", Instant.now()),
70+
"ExecutionReport",
71+
mapOf("encode-mode" to "dirty"),
72+
PROTOCOL,
73+
mapOf(
74+
"header" to mapOf(
75+
"MsgSeqNum" to "10947",
76+
"SenderCompID" to "SENDER",
77+
"SendingTime" to "2023-04-19T10:36:07.415088",
78+
"TargetCompID" to "RECEIVER",
79+
"BeginString" to "FIXT.1.1",
80+
"BodyLength" to "295",
81+
"MsgType" to "8"
82+
),
83+
"ExecID" to "495504662",
84+
"ClOrdID" to "zSuNbrBIZyVljs",
85+
"OrigClOrdID" to "zSuNbrBIZyVljs",
86+
"OrderID" to "49415882",
87+
"ExecType" to '0',
88+
"OrdStatus" to '0',
89+
"LeavesQty" to "500",
90+
"CumQty" to "500",
91+
"SecurityID" to "NWDR",
92+
"SecurityIDSource" to "8",
93+
"TradingParty" to mapOf(
94+
"NoPartyIDs" to listOf(
95+
mapOf(
96+
"PartyID" to "NGALL1FX01",
97+
"PartyIDSource" to "D",
98+
"PartyRole" to "76"
99+
),
100+
mapOf(
101+
"PartyID" to "0",
102+
"PartyIDSource" to "P",
103+
"PartyRole" to "3"
104+
)
105+
)
106+
),
107+
"Account" to "test",
108+
"OrdType" to "A",
109+
"TimeInForce" to "0",
110+
"Side" to "B",
111+
"Symbol" to "ABC",
112+
"OrderQty" to "500",
113+
"Price" to "1000",
114+
"Unknown" to "500",
115+
"TransactTime" to "2018-02-05T10:38:08.000008",
116+
"trailer" to mapOf(
117+
"CheckSum" to "191"
118+
)
119+
)
120+
)
121+
}
122+
}
123+
124+
open class FixNgCodecBenchmark {
125+
@Benchmark
126+
@BenchmarkMode(Mode.Throughput)
127+
fun encodeFixMessage(state: BenchmarkState) {
128+
state.codec.encode(state.parsedGroup, context)
129+
}
130+
131+
@Benchmark
132+
@BenchmarkMode(Mode.Throughput)
133+
fun parseFixMessage(state: BenchmarkState) {
134+
state.codec.decode(state.rawGroup, context)
135+
}
136+
137+
companion object {
138+
private val context = object : IReportingContext {
139+
override fun warning(message: String) { }
140+
override fun warnings(messages: Iterable<String>) { }
141+
}
142+
}
143+
}

0 commit comments

Comments
 (0)