1+ using BenchmarkDotNet . Attributes ;
2+ using BenchmarkDotNet . Configs ;
3+ using BenchmarkDotNet . Jobs ;
4+
5+ namespace Hashids . net . benchmark
6+ {
7+ [ MemoryDiagnoser ]
8+ [ MemoryRandomization ]
9+ [ DisassemblyDiagnoser ]
10+ [ SimpleJob ( RuntimeMoniker . Net48 ) ]
11+ [ SimpleJob ( RuntimeMoniker . Net50 ) ]
12+ [ SimpleJob ( RuntimeMoniker . Net60 ) ]
13+ [ GroupBenchmarksBy ( BenchmarkLogicalGroupRule . ByJob ) ]
14+ public class HashBenchmarks
15+ {
16+ private readonly HashidsNet . Hashids _hashids ;
17+ private readonly int [ ] _ints = { 12345 , 1234567890 , int . MaxValue } ;
18+ private readonly long [ ] _longs = { 12345 , 1234567890123456789 , long . MaxValue } ;
19+ private readonly string _hex = "507f1f77bcf86cd799439011" ;
20+
21+ public HashBenchmarks ( )
22+ {
23+ _hashids = new HashidsNet . Hashids ( ) ;
24+ }
25+
26+ [ Benchmark ]
27+ public void RoundtripInts ( )
28+ {
29+ var encodedValue = _hashids . Encode ( _ints ) ;
30+ var decodedValue = _hashids . Decode ( encodedValue ) ;
31+ }
32+
33+ [ Benchmark ]
34+ public void RoundtripLongs ( )
35+ {
36+ var encodedValue = _hashids . EncodeLong ( _longs ) ;
37+ var decodedValue = _hashids . DecodeLong ( encodedValue ) ;
38+ }
39+
40+ [ Benchmark ]
41+ public void RoundtripHex ( )
42+ {
43+ var encodedValue = _hashids . EncodeHex ( _hex ) ;
44+ var decodedValue = _hashids . DecodeHex ( encodedValue ) ;
45+ }
46+
47+ [ Benchmark ]
48+ public void SingleNumber ( )
49+ {
50+ var encoded = _hashids . Encode ( 5 ) ;
51+ var encodeLong = _hashids . EncodeLong ( 5 ) ;
52+ }
53+
54+ [ Benchmark ]
55+ public void SingleNumberAsParams ( )
56+ {
57+ var encoded = _hashids . Encode ( new [ ] { 1 } ) ;
58+ var encodedLong = _hashids . EncodeLong ( new [ ] { ( long ) 1 } ) ;
59+ }
60+ }
61+ }
0 commit comments