Reprinted from: http://www.cnblogs.com/Leo_wl/p/5918279.html. NET Core Performance test component Benchmarkdotnet support. NET Framework Mono
The. NET core Super Performance Test component Benchmarkdotnet supports the full. NET Framework,. NET core (RTM), Mono.
Benchmarkdotnet supports C #, F #, and Visual Basic, which can be run across platforms.
and support a variety of report export, quite convenient.
Github:https://github.com/perfdotnet/benchmarkdotnet
Let's do the actual use and experience.
This article mainly explains the use of benchmarkdotnet in. NET Core applications.
New app
First we create a new. NET Core Console App Netcoretest
Installing Benchmarkdotnet
To install using the NuGet command line:
Install-package benchmarkdotnet
You can also search for an installation in the NuGet Manager
Writing code
After installation, we can write test code.
Create a new md5vssha256 class and add the benchmark attribute to the method
public class md5vssha256 { Private const int N = 10000; Private readonly byte[] data; Private readonly SHA256 sha256 = SHA256. Create (); Private readonly MD5 MD5 = MD5. Create (); Public md5vssha256 () { data = new Byte[n]; New Random (42). Nextbytes (data); } [Benchmark] Public byte[] Sha256 () { return Sha256.computehash (data); } [Benchmark] Public byte[] Md5 () { return Md5.computehash (data); } }
Perform tests
Let's do it now.
In Program.cs Main, add the following code:
var summary = benchmarkrunner.run<md5vssha256> ();
Then execute the program, you can use the dotnet run can also use vs Debug.
The following is the result of the console output
After execution, there will be a benchmarkdotnet.artifacts folder under the program directory.
There will also be a corresponding test result file.
Benchmarkdotnet (performance test)