1- // See https://aka.ms/new-console-template for more information
2- using System ;
3- using System . Security . Cryptography ;
4- using BenchmarkDotNet . Attributes ;
1+ using BenchmarkDotNet . Configs ;
2+ using BenchmarkDotNet . Diagnosers ;
53using BenchmarkDotNet . Running ;
4+ using Benchmarks ;
5+ using MessagePack ;
66
7- namespace MsgPack . Benchmarks ;
7+ var msg1 = MessagePackSerializer . Serialize ( Location . Sample ) ;
8+ var msg2 = Serde . MsgPack . MsgPackSerializer . Serialize ( Location . Sample ) ;
89
9- public class MessagePackUnit
10+ if ( ! msg1 . SequenceEqual ( msg2 ) )
1011{
11- private const int N = 10000 ;
12- private readonly byte [ ] data ;
13-
14- private readonly SHA256 sha256 = SHA256 . Create ( ) ;
15- private readonly MD5 md5 = MD5 . Create ( ) ;
16-
17- public MessagePackUnit ( )
18- {
19- data = new byte [ N ] ;
20- new Random ( 42 ) . NextBytes ( data ) ;
21- }
22-
23- [ Benchmark ]
24- public byte [ ] Sha256 ( ) => sha256 . ComputeHash ( data ) ;
25-
26- [ Benchmark ]
27- public byte [ ] Md5 ( ) => md5 . ComputeHash ( data ) ;
12+ Console . WriteLine ( string . Join ( ", " , msg1 ) ) ;
13+ Console . WriteLine ( string . Join ( ", " , msg2 ) ) ;
14+ throw new InvalidOperationException ( "bytes do not match" ) ;
2815}
2916
30- public class Program
17+ var loc1 = MessagePackSerializer . Deserialize < Location > ( msg1 ) ;
18+ var loc2 = Serde . MsgPack . MsgPackSerializer . Deserialize < Location , LocationWrap > ( msg1 , LocationWrap . Instance ) ;
19+
20+ Console . WriteLine ( "Checking correctness of serialization: " + ( loc1 == loc2 ) ) ;
21+ if ( loc1 != loc2 )
3122{
32- public static void Main ( string [ ] args )
33- {
34- var summary = BenchmarkRunner . Run < MessagePackUnit > ( ) ;
35- }
23+ throw new InvalidOperationException ( $ """
24+ Serialization is not correct
25+ STJ:
26+ { loc1 }
27+
28+ Serde:
29+ { loc2 }
30+ """ ) ;
3631}
3732
33+ var config = DefaultConfig . Instance . AddDiagnoser ( MemoryDiagnoser . Default ) ;
34+ var summary = BenchmarkSwitcher . FromAssembly ( typeof ( DeserializeFromString < , > ) . Assembly )
35+ . Run ( args , config ) ;
0 commit comments