Table of Contents

Sample: IntroStatisticsColumns

Source code

using System;
using System.Security.Cryptography;
using BenchmarkDotNet.Attributes;

namespace BenchmarkDotNet.Samples
{
    [MediumRunJob, SkewnessColumn, KurtosisColumn]
    public class IntroStatisticsColumns
    {
        private const int N = 10000;
        private readonly byte[] data;

        private readonly MD5 md5 = MD5.Create();
        private readonly SHA256 sha256 = SHA256.Create();

        public IntroStatisticsColumns()
        {
            data = new byte[N];
            new Random(42).NextBytes(data);
        }

        [Benchmark(Baseline = true)]
        public byte[] Md5A() => md5.ComputeHash(data);

        [Benchmark]
        public byte[] Md5B() => md5.ComputeHash(data);

        [Benchmark]
        public byte[] Sha256() => sha256.ComputeHash(data);
    }
}

Output

Method Mean Error StdDev Skewness Kurtosis Ratio RatioSD
Md5A 15.91 us 0.0807 us 0.1209 us 0.4067 1.646 1.00 0.00
Md5B 15.89 us 0.0709 us 0.1062 us 0.5893 2.141 1.00 0.01
Sha256 36.62 us 0.6390 us 0.9564 us 1.1363 4.014 2.30 0.06