1+ using SerializersBenchmark ;
2+ using SerializersBenchmark . Models ;
3+ using SerializersBenchmark . Serializers ;
4+ using Xunit ;
5+
6+ namespace SerializerBenchmarks . UnitTests ;
7+
8+ public sealed class AsyncBenchmarkTests : IDisposable
9+ {
10+ private static int _portNumber = 27003 ;
11+ private static int GetNextPort ( )
12+ {
13+ Interlocked . Increment ( ref _portNumber ) ;
14+ return _portNumber ;
15+ }
16+
17+ private readonly AsyncBenchmarks _benchmark = new ( )
18+ {
19+ N = 1 ,
20+ QueueLength = 7 ,
21+ BlackHolePort = GetNextPort ( ) ,
22+ WhiteHolePort = GetNextPort ( )
23+ } ;
24+
25+ [ Theory ( Timeout = 1000 ) ]
26+ [ InlineData ( typeof ( Ceras < DataItem > ) ) ]
27+ [ InlineData ( typeof ( Utf8JsonSerializer < DataItem > ) ) ]
28+ [ InlineData ( typeof ( MessagePack < DataItem > ) ) ]
29+ [ InlineData ( typeof ( GroBuf < DataItem > ) ) ]
30+ [ InlineData ( typeof ( Bois < DataItem > ) ) ]
31+ [ InlineData ( typeof ( BoisLz4 < DataItem > ) ) ]
32+ [ InlineData ( typeof ( Jil < DataItem > ) ) ]
33+ [ InlineData ( typeof ( ProtobufNet < DataItem > ) ) ]
34+ [ InlineData ( typeof ( GoogleProtobuf < ProtobufDataItem > ) ) ]
35+ [ InlineData ( typeof ( ServiceStack < DataItem > ) ) ]
36+ [ InlineData ( typeof ( FastJson < DataItem > ) ) ]
37+ [ InlineData ( typeof ( DataContractBinaryXml < DataItem > ) ) ]
38+ [ InlineData ( typeof ( DataContract < DataItem > ) ) ]
39+ [ InlineData ( typeof ( XmlSerializer < DataItem > ) ) ]
40+ [ InlineData ( typeof ( NewtonsoftJson < DataItem > ) ) ]
41+ [ InlineData ( typeof ( MsgPackCli < DataItem > ) ) ]
42+ [ InlineData ( typeof ( SystemTextJson < DataItem > ) ) ]
43+ #if ( NET6_0_OR_GREATER )
44+ [ InlineData ( typeof ( MemoryPack < DataItem > ) ) ]
45+ [ InlineData ( typeof ( BinaryPack < DataItem > ) ) ]
46+ [ InlineData ( typeof ( SpanJson < DataItem > ) ) ]
47+ [ InlineData ( typeof ( SystemTextJsonSourceGen < DataItem > ) ) ]
48+ #endif
49+ #if NET48
50+ [ InlineData ( typeof ( BinaryFormatter < DataItem > ) ) ]
51+ #endif
52+ public async Task SerializeAsyncTest ( Type serializerType )
53+ {
54+ _benchmark . SerializerType = serializerType ;
55+ await _benchmark . SetupAsync ( ) ;
56+ await _benchmark . SerializeAsync ( ) ;
57+ }
58+
59+ [ Theory ( Timeout = 1000 ) ]
60+ [ InlineData ( typeof ( Ceras < DataItem > ) ) ]
61+ [ InlineData ( typeof ( Utf8JsonSerializer < DataItem > ) ) ]
62+ [ InlineData ( typeof ( MessagePack < DataItem > ) ) ]
63+ [ InlineData ( typeof ( GroBuf < DataItem > ) ) ]
64+ [ InlineData ( typeof ( Bois < DataItem > ) ) ]
65+ [ InlineData ( typeof ( BoisLz4 < DataItem > ) ) ]
66+ [ InlineData ( typeof ( Jil < DataItem > ) ) ]
67+ [ InlineData ( typeof ( ProtobufNet < DataItem > ) ) ]
68+ [ InlineData ( typeof ( GoogleProtobuf < ProtobufDataItem > ) ) ]
69+ [ InlineData ( typeof ( ServiceStack < DataItem > ) ) ]
70+ [ InlineData ( typeof ( FastJson < DataItem > ) ) ]
71+ [ InlineData ( typeof ( DataContractBinaryXml < DataItem > ) ) ]
72+ [ InlineData ( typeof ( DataContract < DataItem > ) ) ]
73+ [ InlineData ( typeof ( XmlSerializer < DataItem > ) ) ]
74+ [ InlineData ( typeof ( NewtonsoftJson < DataItem > ) ) ]
75+ [ InlineData ( typeof ( MsgPackCli < DataItem > ) ) ]
76+ [ InlineData ( typeof ( SystemTextJson < DataItem > ) ) ]
77+ #if ( NET6_0_OR_GREATER )
78+ [ InlineData ( typeof ( MemoryPack < DataItem > ) ) ]
79+ [ InlineData ( typeof ( BinaryPack < DataItem > ) ) ]
80+ [ InlineData ( typeof ( SpanJson < DataItem > ) ) ]
81+ [ InlineData ( typeof ( SystemTextJsonSourceGen < DataItem > ) ) ]
82+ #endif
83+ #if NET48
84+ [ InlineData ( typeof ( BinaryFormatter < DataItem > ) ) ]
85+ #endif
86+ public async Task BufferedSerializeAsyncTest ( Type serializerType )
87+ {
88+ _benchmark . SerializerType = serializerType ;
89+ _benchmark . UseBuffer = true ;
90+ await _benchmark . SetupAsync ( ) ;
91+ await _benchmark . SerializeAsync ( ) ;
92+ }
93+
94+ [ Theory ( Timeout = 1000 ) ]
95+ [ InlineData ( typeof ( Ceras < DataItem > ) ) ]
96+ [ InlineData ( typeof ( Utf8JsonSerializer < DataItem > ) ) ]
97+ [ InlineData ( typeof ( MessagePack < DataItem > ) ) ]
98+ [ InlineData ( typeof ( GroBuf < DataItem > ) ) ]
99+ [ InlineData ( typeof ( Bois < DataItem > ) ) ]
100+ [ InlineData ( typeof ( BoisLz4 < DataItem > ) ) ]
101+ [ InlineData ( typeof ( Jil < DataItem > ) ) ]
102+ [ InlineData ( typeof ( ProtobufNet < DataItem > ) ) ]
103+ [ InlineData ( typeof ( GoogleProtobuf < ProtobufDataItem > ) ) ]
104+ [ InlineData ( typeof ( ServiceStack < DataItem > ) ) ]
105+ [ InlineData ( typeof ( FastJson < DataItem > ) ) ]
106+ [ InlineData ( typeof ( DataContractBinaryXml < DataItem > ) ) ]
107+ [ InlineData ( typeof ( DataContract < DataItem > ) ) ]
108+ [ InlineData ( typeof ( XmlSerializer < DataItem > ) ) ]
109+ [ InlineData ( typeof ( NewtonsoftJson < DataItem > ) ) ]
110+ [ InlineData ( typeof ( MsgPackCli < DataItem > ) ) ]
111+ [ InlineData ( typeof ( SystemTextJson < DataItem > ) ) ]
112+ #if ( NET6_0_OR_GREATER )
113+ [ InlineData ( typeof ( MemoryPack < DataItem > ) ) ]
114+ [ InlineData ( typeof ( BinaryPack < DataItem > ) ) ]
115+ [ InlineData ( typeof ( SpanJson < DataItem > ) ) ]
116+ [ InlineData ( typeof ( SystemTextJsonSourceGen < DataItem > ) ) ]
117+ #endif
118+ #if NET48
119+ [ InlineData ( typeof ( BinaryFormatter < DataItem > ) ) ]
120+ #endif
121+ public async Task DeserializeAsyncTest ( Type serializerType )
122+ {
123+ _benchmark . SerializerType = serializerType ;
124+ await _benchmark . SetupAsync ( ) ;
125+ await _benchmark . DeserializeAsync ( ) ;
126+ }
127+
128+ [ Theory ( Timeout = 1000 ) ]
129+ [ InlineData ( typeof ( Ceras < DataItem > ) ) ]
130+ [ InlineData ( typeof ( Utf8JsonSerializer < DataItem > ) ) ]
131+ [ InlineData ( typeof ( MessagePack < DataItem > ) ) ]
132+ [ InlineData ( typeof ( GroBuf < DataItem > ) ) ]
133+ [ InlineData ( typeof ( Bois < DataItem > ) ) ]
134+ [ InlineData ( typeof ( BoisLz4 < DataItem > ) ) ]
135+ [ InlineData ( typeof ( Jil < DataItem > ) ) ]
136+ [ InlineData ( typeof ( ProtobufNet < DataItem > ) ) ]
137+ [ InlineData ( typeof ( GoogleProtobuf < ProtobufDataItem > ) ) ]
138+ [ InlineData ( typeof ( ServiceStack < DataItem > ) ) ]
139+ [ InlineData ( typeof ( FastJson < DataItem > ) ) ]
140+ [ InlineData ( typeof ( DataContractBinaryXml < DataItem > ) ) ]
141+ [ InlineData ( typeof ( DataContract < DataItem > ) ) ]
142+ [ InlineData ( typeof ( XmlSerializer < DataItem > ) ) ]
143+ [ InlineData ( typeof ( NewtonsoftJson < DataItem > ) ) ]
144+ [ InlineData ( typeof ( MsgPackCli < DataItem > ) ) ]
145+ [ InlineData ( typeof ( SystemTextJson < DataItem > ) ) ]
146+ #if ( NET6_0_OR_GREATER )
147+ [ InlineData ( typeof ( MemoryPack < DataItem > ) ) ]
148+ [ InlineData ( typeof ( BinaryPack < DataItem > ) ) ]
149+ [ InlineData ( typeof ( SpanJson < DataItem > ) ) ]
150+ [ InlineData ( typeof ( SystemTextJsonSourceGen < DataItem > ) ) ]
151+ #endif
152+ #if NET48
153+ [ InlineData ( typeof ( BinaryFormatter < DataItem > ) ) ]
154+ #endif
155+ public async Task BufferedDeserializeAsyncTest ( Type serializerType )
156+ {
157+ _benchmark . SerializerType = serializerType ;
158+ _benchmark . UseBuffer = true ;
159+ await _benchmark . SetupAsync ( ) ;
160+ await _benchmark . DeserializeAsync ( ) ;
161+ }
162+
163+ public void Dispose ( )
164+ {
165+ _benchmark . Cleanup ( ) ;
166+ }
167+ }
0 commit comments