-
Notifications
You must be signed in to change notification settings - Fork 272
/
Hashing.cs
29 lines (24 loc) · 1017 Bytes
/
Hashing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Linq;
using BenchmarkDotNet.Attributes;
using MicroBenchmarks;
namespace System
{
[BenchmarkCategory(Categories.Runtime, Categories.Libraries)]
public class Hashing
{
private string _string;
[Params(10, 100, 1_000, 10_000)]
public int BytesCount;
/// <summary>
/// Marvin is internal, this is why we call string.GetHashCode to measure it's performance
/// see https://github.com/dotnet/corefx/blob/8252ecc2eb0da08cd474a303b646e111d74d2a71/src/Common/src/CoreLib/System/String.Comparison.cs#L749
/// </summary>
[GlobalSetup]
public void Setup() => _string = new string('a', BytesCount / (sizeof(char)/ sizeof(byte)));
[Benchmark]
public int GetStringHashCode() => _string.GetHashCode();
}
}