1
- [ ![ Quality Gate Status] ( https://sonarcloud.io/api/project_badges/measure?project=nanoframework_nanoFramework.MessagePack&metric=alert_status )] ( https://sonarcloud.io/dashboard?id=nanoframework_nanoFramework.MessagePack ) [ ![ Reliability Rating] ( https://sonarcloud.io/api/project_badges/measure?project=nanoframework_nanoFramework.MessagePack&metric=reliability_rating )] ( https://sonarcloud.io/dashboard?id=nanoframework_nanoFramework.MessagePack ) [ ![ NuGet] ( https://img.shields.io/nuget/dt/nanoFramework.MessagePack.svg?label=NuGet&style=flat&logo=nuget )] ( https://www.nuget.org/packages/nanoFramework.MessagePack/ ) [ ![ #yourfirstpr] ( https://img.shields.io/badge/first--timers--only-friendly-blue.svg )] ( https://github.com/nanoframework/Home/blob/main/CONTRIBUTING.md ) [ ![ Discord] ( https://img.shields.io/discord/478725473862549535.svg?logo=discord&logoColor=white&label=Discord&color=7289DA )] ( https://discord.gg/gCyBu8T )
1
+ [ ![ Quality Gate Status] ( https://sonarcloud.io/api/project_badges/measure?project=nanoframework_nanoFramework.MessagePack&metric=alert_status )] ( https://sonarcloud.io/dashboard?id=nanoframework_nanoFramework.MessagePack ) [ ![ Reliability Rating] ( https://sonarcloud.io/api/project_badges/measure?project=nanoframework_nanoFramework.MessagePack&metric=reliability_rating )] ( https://sonarcloud.io/dashboard?id=nanoframework_nanoFramework.MessagePack ) [ ![ NuGet] ( https://img.shields.io/nuget/dt/nanoFramework.MessagePack.svg?label=NuGet&style=flat&logo=nuget )] ( https://www.nuget.org/packages/nanoFramework.MessagePack/ ) [ ![ #yourfirstpr] ( https://img.shields.io/badge/first--timers--only-friendly-blue.svg )] ( https://github.com/nanoframework/Home/blob/main/CONTRIBUTING.md ) [ ![ Discord] ( https://img.shields.io/discord/478725473862549535.svg?logo=discord&logoColor=white&label=Discord&color=7289DA )] ( https://discord.gg/gCyBu8T )
2
2
3
3
![ nanoFramework logo] ( https://raw.githubusercontent.com/nanoframework/Home/main/resources/logo/nanoFramework-repo-logo.png )
4
4
@@ -151,7 +151,7 @@ After completing these steps, the serialization/deserialization of the object fo
151
151
{
152
152
WordDictionary = new ArrayList
153
153
{
154
- " MessagePak " ,
154
+ " MessagePack " ,
155
155
" Hello" ,
156
156
" at" ,
157
157
" nanoFramework!" ,
@@ -178,30 +178,33 @@ After completing these steps, the serialization/deserialization of the object fo
178
178
{
179
179
StringBuilder sb = new ();
180
180
var length = reader .ReadArrayLength ();
181
-
182
- for (int i = 0 ; i < length ; i ++ )
181
+ var intConverter = ConverterContext .GetConverter (typeof (int ));
182
+
183
+ for (int i = 0 ; i < length ; i ++ )
183
184
{
184
- sb .Append (SharedWordDictionary .WordDictionary [i ]);
185
+ int wordIndex = (int )intConverter .Read (reader )! ;
186
+ sb .Append (SharedWordDictionary .WordDictionary [wordIndex ]);
185
187
sb .Append (' ' );
186
188
}
187
189
if (sb .Length > 0 )
188
190
sb .Remove (sb .Length - 1 , 1 );
189
-
191
+
190
192
return new SecureMessage (sb .ToString ());
191
193
}
192
-
194
+
193
195
public void Write (SecureMessage value , [NotNull ] IMessagePackWriter writer )
194
196
{
195
197
var messageWords = value .Message .Split (' ' );
196
-
197
- uint length = BitConverter . ToUInt32 ( BitConverter . GetBytes ( messageWords .Length ), 0 ) ;
198
+
199
+ uint length = ( uint ) messageWords .Length ;
198
200
writer .WriteArrayHeader (length );
199
-
201
+
200
202
var intConverter = ConverterContext .GetConverter (typeof (int ));
201
-
203
+
202
204
foreach (var word in messageWords )
203
205
{
204
- intConverter .Write (SharedWordDictionary .WordDictionary .IndexOf (word ), writer );
206
+ int wordIndex = SharedWordDictionary .WordDictionary .IndexOf (word );
207
+ intConverter .Write (wordIndex , writer );
205
208
}
206
209
}
207
210
@@ -245,6 +248,43 @@ After completing these steps, the serialization/deserialization of the object fo
245
248
}
246
249
```
247
250
251
+ ## Benchmarks
252
+
253
+ The measurements were carried out on the developer's local computer in a virtual nanoDevice:
254
+
255
+ ``` text
256
+ ===============================================================
257
+ ========== Comparative benchmarks data ==========
258
+ ========== ==========
259
+ ========== Json string size: 3957 bytes ==========
260
+ ========== BinaryFormatter array size: 1079 bytes ==========
261
+ ========== MessagePack array size: 2444 bytes ==========
262
+ ========== ==========
263
+ ===============================================================
264
+
265
+ Console export: ComparativeDeserializationBenchmark benchmark class.
266
+
267
+ | ------------------------------------------------------------------------------ |
268
+ | MethodName | IterationCount | Mean | Min | Max |
269
+ | ------------------------------------------------------------------------------ |
270
+ | JsonDeserializationBenchmark | 10 | 27.5 ms | 22 ms | 37 ms |
271
+ | BinaryDeserializationBenchmark | 10 | 0.1 ms | 0 ms | 1 ms |
272
+ | MessagePackDeserializationBenchmark | 10 | 23.7 ms | 19 ms | 34 ms |
273
+ | ------------------------------------------------------------------------------ |
274
+
275
+ Console export: ComparativeSerializationBenchmark benchmark class.
276
+
277
+
278
+ | ---------------------------------------------------------------------------- |
279
+ | MethodName | IterationCount | Mean | Min | Max |
280
+ | ---------------------------------------------------------------------------- |
281
+ | JsonSerializationBenchmark | 10 | 18.9 ms | 16 ms | 25 ms |
282
+ | BinarySerializationBenchmark | 10 | 0.1 ms | 0 ms | 1 ms |
283
+ | MessagePackSerializationBenchmark | 10 | 9.8 ms | 9 ms | 14 ms |
284
+ | ---------------------------------------------------------------------------- |
285
+ ```
286
+ As it can be seen from the benchmark results above, in what concerns speed and compaction, ` MessagePack ` performs better than the Json serializer. Comming at no surprise, Binary serialization is the most performant one.
287
+
248
288
## Acknowledgements
249
289
250
290
The initial version of the MessagePack library was coded by [ Spirin Dmitriy] ( https://github.com/RelaxSpirit ) , who has kindly handed over the library to the .NET ** nanoFramework** project.
0 commit comments