A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System;
5using System.IO;
6using BenchmarkDotNet.Attributes;
7using osu.Framework.Extensions;
8
9namespace osu.Framework.Benchmarks
10{
11 [MemoryDiagnoser]
12 public class BenchmarkHashing
13 {
14 private const string test_string = @"A string with reasonable length";
15 private MemoryStream memoryStream;
16
17 [Benchmark]
18 public string StringMD5() => test_string.ComputeMD5Hash();
19
20 [Benchmark]
21 public string StringSHA() => test_string.ComputeSHA2Hash();
22
23 [GlobalSetup]
24 public void GlobalSetup()
25 {
26 byte[] array = new byte[1024];
27 var random = new Random(42);
28 random.NextBytes(array);
29 memoryStream = new MemoryStream(array);
30 }
31
32 [Benchmark]
33 public string StreamMD5() => memoryStream.ComputeMD5Hash();
34
35 [Benchmark]
36 public string StreamSHA() => memoryStream.ComputeSHA2Hash();
37 }
38}