Extremely fast non-cryptographic hash algorithm xxhash
xxHash is an Extremely fast Hash algorithm, running at RAM speed limits. It successfully completes the SMHasher test suite which evaluates collision, dispersion and randomness qualities of hash functions.
PM> Install-Package Standart.Hash.xxHash
This benchmark was launched on a Windows 10.0.19044.1706 (21H2). The reference system uses a AMD Ryzen 7 2700, 1 CPU, 16 logical and 8 physical cores
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19044.1706 (21H2)
AMD Ryzen 7 2700, 1 CPU, 16 logical and 8 physical cores
.NET SDK=6.0.300
[Host] : .NET 6.0.5 (6.0.522.21309), X64 RyuJIT
Job-HQVLOG : .NET 6.0.5 (6.0.522.21309), X64 RyuJIT
Runtime=.NET 6.0 | Method | x64 |
|---|---|
| Hash32 Array | 6.65 GB/s |
| Hash64 Array | 12.28 GB/s |
| Hash128 Array | 12.04 GB/s |
| Hash3 Array | 12.08 GB/s |
| Hash32 Span | 6.65 GB/s |
| Hash64 Span | 12.28 GB/s |
| Hash128 Span | 12.04 GB/s |
| Hash3 Span | 12.08 GB/s |
| Hash32 Stream | 3.22 GB/s |
| Hash64 Stream | 4.81 GB/s |
| Method | Platform | Language | 1KB Time | 1MB Time | 1GB Time | Speed |
|---|---|---|---|---|---|---|
| Hash32 | x64 | C# | 138.0 ns | 130.2 us | 150.3 ms | 6.65 GB/s |
| Hash32 | x64 | C | 140.2 ns | 129.6 us | 150.3 ms | 6.65 GB/s |
| Hash64 | x64 | C# | 73.9 ns | 64.6 us | 81.4 ms | 12.28 GB/s |
| Hash64 | x64 | C | 75.5 ns | 65.2 us | 84.5 ms | 11.83 GB/s |
| Hash128 (SSE2/AVX2) | x64 | C# | 84.95 ns | 56.9 us | 73.2 ms | 13.66 GB/s |
| Hash128 (SSE2/AVX2) | x64 | C | 84.35 ns | 38.1 us | 57.2 ms | 17.48 GB/s |
| Hash3 (SSE2/AVX2) | x64 | C# | 75.8 ns | 56.6 us | 74.6 ms | 13.40 GB/s |
| Hash3 (SSE2/AVX2) | x64 | C | 74.1 ns | 42.1 us | 59.5 ms | 16.80 GB/s |
publicstaticuintComputeHash(byte[]data,intlength,uintseed=0){thrownull;}publicstaticuintComputeHash(Span<byte>data,intlength,uintseed=0){thrownull;}publicstaticuintComputeHash(Streamstream,intbufferSize=4096,uintseed=0){thrownull;}publicstaticasyncValueTask<uint>ComputeHashAsync(Streamstream,intbufferSize=4096,uintseed=0){thrownull;}publicstaticuintComputeHash(stringstr,uintseed=0){thrownull;}publicstaticulongComputeHash(byte[]data,intlength,ulongseed=0){thrownull;}publicstaticulongComputeHash(Span<byte>data,intlength,ulongseed=0){thrownull;}publicstaticulongComputeHash(Streamstream,intbufferSize=8192,ulongseed=0){thrownull;}publicstaticasyncValueTask<ulong>ComputeHashAsync(Streamstream,intbufferSize=8192,ulongseed=0){thrownull;}publicstaticulongComputeHash(stringstr,uintseed=0){thrownull;}publicstaticuint128ComputeHash(byte[]data,intlength,uintseed=0){thrownull;}publicstaticuint128ComputeHash(Span<byte>data,intlength,uintseed=0){thrownull;}publicstaticuint128ComputeHash(stringstr,uintseed=0){thrownull;}// allocationspublicstaticbyte[]ComputeHashBytes(byte[]data,intlength,uintseed=0){thrownull;}publicstaticbyte[]ComputeHashBytes(Span<byte>data,intlength,uintseed=0){thrownull;}publicstaticbyte[]ComputeHashBytes(stringstr,uintseed=0){thrownull;}A few examples of how to use api
byte[]data=Encoding.UTF8.GetBytes("veni vidi vici");ulongh64_1=xxHash64.ComputeHash(data,data.Length);ulongh64_2=xxHash64.ComputeHash(newSpan<byte>(data),data.Length);ulongh64_3=xxHash64.ComputeHash(newReadOnlySpan<byte>(data),data.Length);ulongh64_4=xxHash64.ComputeHash(newMemoryStream(data));ulongh64_5=awaitxxHash64.ComputeHashAsync(newMemoryStream(data));ulongh64_6=xxHash64.ComputeHash("veni vidi vici");uinth32_1=xxHash32.ComputeHash(data,data.Length);uinth32_2=xxHash32.ComputeHash(newSpan<byte>(data),data.Length);uinth32_3=xxHash32.ComputeHash(newReadOnlySpan<byte>(data),data.Length);uinth32_4=xxHash32.ComputeHash(newMemoryStream(data));uinth32_5=awaitxxHash32.ComputeHashAsync(newMemoryStream(data));uinth32_6=xxHash32.ComputeHash("veni vidi vici");ulongh3_1=xxHash3.ComputeHash(data,data.Length);ulongh3_2=xxHash3.ComputeHash(newSpan<byte>(data),data.Length);ulongh3_3=xxHash3.ComputeHash(newReadOnlySpan<byte>(data),data.Length);ulongh3_4=xxHash3.ComputeHash("veni vidi vici");uint128h128_1=xxHash128.ComputeHash(data,data.Length);uint128h128_2=xxHash128.ComputeHash(newSpan<byte>(data),data.Length);uint128h128_3=xxHash128.ComputeHash(newReadOnlySpan<byte>(data),data.Length);uint128h128_4=xxHash128.ComputeHash("veni vidi vici");Guidguid=h128_1.ToGuid();byte[]bytes=h128_1.ToBytes();byte[]hash_bytes_1=xxHash128.ComputeHashBytes(data,data.Length);byte[]hash_bytes_2=xxHash128.ComputeHashBytes(newSpan<byte>(data),data.Length);byte[]hash_bytes_3=xxHash128.ComputeHashBytes(newReadOnlySpan<byte>(data),data.Length);byte[]hash_bytes_4=xxHash128.ComputeHashBytes("veni vidi vici");Made in 🔰 Ukraine with ❤️
