-
-
Notifications
You must be signed in to change notification settings - Fork 560
/
HashBenchmark.cs
35 lines (28 loc) · 908 Bytes
/
HashBenchmark.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
30
31
32
33
34
35
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Order;
using Jint.Extensions;
namespace Jint.Benchmark;
[RankColumn]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByParams)]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class HashBenchmark
{
[Params("i", "str", "Math", "encodeURIComponent")]
public string Input { get; set; }
[Benchmark(Baseline = true)]
public int StringHashCode() => Input.GetHashCode();
[Benchmark]
public int StringOrdinalHashCode() => StringComparer.Ordinal.GetHashCode(Input);
[Benchmark]
public int Fnv1() => Hash.GetFNVHashCode(Input);
/*
[Benchmark]
public ulong Hash3()
{
Span<byte> s1 = stackalloc byte[Input.Length * 2];
Encoding.UTF8.TryGetBytes(Input, s1, out var written);
return System.IO.Hashing.XxHash3.HashToUInt64(s1[..written]);
}
*/
}