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\u0001 9=295\u0001 35=8\u0001 49=SENDER\u0001 56=RECEIVER\u0001 34=10947\u0001 52=20230419-10:36:07.415088\u0001 17=495504662\u0001 11=zSuNbrBIZyVljs\u0001 41=zSuNbrBIZyVljs\u0001 37=49415882\u0001 150=0\u0001 39=0\u0001 151=500\u0001 14=500\u0001 48=NWDR\u0001 22=8\u0001 453=2\u0001 448=NGALL1FX01\u0001 447=D\u0001 452=76\u0001 448=0\u0001 447=P\u0001 452=3\u0001 1=test\u0001 40=A\u0001 59=0\u0001 54=B\u0001 55=ABC\u0001 38=500\u0001 44=1000\u0001 47=500\u0001 60=20180205-10:38:08.000008\u0001 10=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