Benchmarkdotnet (performance test)

Source: Internet
Author: User
Tags benchmark

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)

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.