. NET Core performance testing component BenchmarkDotNet supports. NET Framework Mono and benchmarkdotnet

Source: Internet
Author: User

. NET Core performance testing component BenchmarkDotNet supports. NET Framework Mono and benchmarkdotnet

BenchmarkDotNet, a super-powerful performance testing component of. NET Core, supports Full. NET Framework,. NET Core (RTM), and Mono.

BenchmarkDotNet supports C #, F #, and Visual Basic, and can be run across platforms.

It also supports export of various reports, which is quite convenient.

GitHub: https://github.com/PerfDotNet/BenchmarkDotNet

Next we will discuss the actual use and experience.

This article describes how to use BenchmarkDotNet in. NET Core applications.

Create an application

First, create a. NET Core console application NETCoreTest.

 

Install BenchmarkDotNet

Use the NuGet command line to install:

Install-Package BenchmarkDotNet

You can also search for installation in NuGet Manager

Write code

After the installation, We can compile the test code.

Create an Md5VsSha256 class and add the Benchmark feature 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);        }    }
Run the test

Next we will execute

Add the following code to Program. cs Main:

var summary = BenchmarkRunner.Run<Md5VsSha256>();

Then run the program. You can use dotnet run or vs DEBUG.

The following figure shows the output result of the console.

 

After execution, a BenchmarkDotNet. Artifacts folder will be created in the program directory.

There will also be a corresponding test result file.

 

 

For more powerful functions, see the official documentation: https://perfdotnet.github.io/BenchmarkDotNet/

 

If you think this article is helpful to you, click"Recommendation", Thank you.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.