A game framework written with osu! in mind.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add benchmark for hashing extensions

+38
+38
osu.Framework.Benchmarks/BenchmarkHashing.cs
··· 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 + 4 + using System; 5 + using System.IO; 6 + using BenchmarkDotNet.Attributes; 7 + using osu.Framework.Extensions; 8 + 9 + namespace 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 + }