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 )
22
33![ nanoFramework logo] ( https://raw.githubusercontent.com/nanoframework/Home/main/resources/logo/nanoFramework-repo-logo.png )
44
@@ -151,7 +151,7 @@ After completing these steps, the serialization/deserialization of the object fo
151151 {
152152 WordDictionary = new ArrayList
153153 {
154- " MessagePak " ,
154+ " MessagePack " ,
155155 " Hello" ,
156156 " at" ,
157157 " nanoFramework!" ,
@@ -178,30 +178,33 @@ After completing these steps, the serialization/deserialization of the object fo
178178 {
179179 StringBuilder sb = new ();
180180 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 ++ )
183184 {
184- sb .Append (SharedWordDictionary .WordDictionary [i ]);
185+ int wordIndex = (int )intConverter .Read (reader )! ;
186+ sb .Append (SharedWordDictionary .WordDictionary [wordIndex ]);
185187 sb .Append (' ' );
186188 }
187189 if (sb .Length > 0 )
188190 sb .Remove (sb .Length - 1 , 1 );
189-
191+
190192 return new SecureMessage (sb .ToString ());
191193 }
192-
194+
193195 public void Write (SecureMessage value , [NotNull ] IMessagePackWriter writer )
194196 {
195197 var messageWords = value .Message .Split (' ' );
196-
197- uint length = BitConverter . ToUInt32 ( BitConverter . GetBytes ( messageWords .Length ), 0 ) ;
198+
199+ uint length = ( uint ) messageWords .Length ;
198200 writer .WriteArrayHeader (length );
199-
201+
200202 var intConverter = ConverterContext .GetConverter (typeof (int ));
201-
203+
202204 foreach (var word in messageWords )
203205 {
204- intConverter .Write (SharedWordDictionary .WordDictionary .IndexOf (word ), writer );
206+ int wordIndex = SharedWordDictionary .WordDictionary .IndexOf (word );
207+ intConverter .Write (wordIndex , writer );
205208 }
206209 }
207210
@@ -245,6 +248,43 @@ After completing these steps, the serialization/deserialization of the object fo
245248 }
246249 ```
247250
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+
248288## Acknowledgements
249289
250290The 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