catcherwong opened a new issue, #581:
URL: https://github.com/apache/rocketmq-clients/issues/581

   ### Before Creating the Enhancement Request
   
   - [X] I have confirmed that this should be classified as an enhancement 
rather than a bug/feature.
   
   
   ### Programming Language of the Client
   
   C#
   
   ### Summary
   
   
https://github.com/apache/rocketmq-clients/blob/1e7aa3327a056296a887ff2e1d12fee45651fd3f/csharp/rocketmq-client-csharp/Signature.cs#L62
   
   When creating a new instance of HMACSHA1, use using to wrap it should be 
better here.
   
   ### Motivation
   
   Using the following code to benchmark the usage of using and without using, 
using works better than without using.
   
   Code:
   
   ```cs
   [MemoryDiagnoser]
   [SimpleJob(RuntimeMoniker.Net50)]
   [SimpleJob(RuntimeMoniker.Net60)]
   [SimpleJob(RuntimeMoniker.Net70)]
   public class HMACSHA1Benchmark
   {
       private readonly byte[] secretData = Encoding.ASCII.GetBytes("123456");
   
       [Benchmark]
       public string Using() => HMACSHA1WithUsing();
   
       [Benchmark]
       public string WithoutUsing() => HMACSHA1WithoutUsing();
   
       private string HMACSHA1WithUsing()
       {
           using (var signer = new HMACSHA1(secretData))
           {
               var digest = 
signer.ComputeHash(Encoding.ASCII.GetBytes(DateTime.Now.ToString()));
               var hmac = BitConverter.ToString(digest).Replace("-", "");
               return hmac;
           }
       }
   
       private string HMACSHA1WithoutUsing()
       {
           var signer = new HMACSHA1(secretData);
           var digest = 
signer.ComputeHash(Encoding.ASCII.GetBytes(DateTime.Now.ToString()));
           var hmac = BitConverter.ToString(digest).Replace("-", "");
           return hmac;
       }
   }
   ```
   
   Result:
   
   BenchmarkDotNet v0.13.6, Windows 10 
(10.0.17763.4644/1809/October2018Update/Redstone5)
   Intel Xeon CPU E5-2620 v4 2.10GHz, 1 CPU, 16 logical and 8 physical cores
   .NET SDK 7.0.203
     [Host]   : .NET 6.0.16 (6.0.1623.17311), X64 RyuJIT AVX2
     .NET 5.0 : .NET 5.0.12 (5.0.1221.52207), X64 RyuJIT AVX2
     .NET 6.0 : .NET 6.0.16 (6.0.1623.17311), X64 RyuJIT AVX2
     .NET 7.0 : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
   
   
   |       Method |      Job |  Runtime |     Mean |     Error |    StdDev |   
Gen0 |   Gen1 | Allocated |
   |------------- |--------- |--------- 
|---------:|----------:|----------:|-------:|-------:|----------:|
   |        Using | .NET 5.0 | .NET 5.0 | 2.795 us | 0.0245 us | 0.0217 us | 
0.0648 |      - |     712 B |
   | WithoutUsing | .NET 5.0 | .NET 5.0 | 3.252 us | 0.0544 us | 0.0483 us | 
0.0648 | 0.0305 |     712 B |
   |        Using | .NET 6.0 | .NET 6.0 | 2.806 us | 0.0274 us | 0.0256 us | 
0.0648 |      - |     712 B |
   | WithoutUsing | .NET 6.0 | .NET 6.0 | 3.062 us | 0.0372 us | 0.0348 us | 
0.0648 | 0.0305 |     712 B |
   |        Using | .NET 7.0 | .NET 7.0 | 2.703 us | 0.0185 us | 0.0145 us | 
0.0648 |      - |     704 B |
   | WithoutUsing | .NET 7.0 | .NET 7.0 | 2.958 us | 0.0340 us | 0.0318 us | 
0.0648 | 0.0610 |     704 B |
   
   ### Describe the Solution You'd Like
   
   When creating a new instance of HMACSHA1, use using to wrap it.
   
   ### Describe Alternatives You've Considered
   
   Nothing
   
   ### Additional Context
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to