net 6 下性能测试
作者:互联网
1 安装BenchmarkDotNet 包
2 写两个算法 方法 sha256 和sha512 标记特性
public class ShaTest { Testa Testa=new Testa(); [Benchmark] public string Sha256A() => Testa.Sha256("http://www.cndns.com"); [Benchmark] public string Sha512B() => Testa.Sha512("http://www.cndns.com"); }
3 方法入口处 添加方法
// See https://aka.ms/new-console-template for more information using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; using Cndns.Test; BenchmarkRunner.Run<ShaTest>(); Console.WriteLine("ok");
4 Release 模式下 ctrl+ F5
| Method | Mean | Error | StdDev | Median |
|-------- |---------:|----------:|----------:|---------:|
| Sha256A | 1.998 us | 0.0734 us | 0.2154 us | 1.932 us |
| Sha512B | 2.069 us | 0.1099 us | 0.3153 us | 1.959 us |
// * Hints *
Outliers
ShaTest.Sha256A: Default -> 1 outlier was removed (2.70 us)
ShaTest.Sha512B: Default -> 5 outliers were removed (3.01 us..3.63 us)
明显 sha256 用时少。。。
标签:BenchmarkDotNet,性能,Sha512B,us,Testa,Sha256A,测试,net,public 来源: https://www.cnblogs.com/jasontarry/p/15638174.html