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 (10.0.16299.309). The reference system uses a Intel Core i7-4700MQ CPU 2.40GHz (Haswell)
| Method | x64 |
|---|---|
| Hash32 Array | 5.05 GB/s |
| Hash64 Array | 8.92 GB/s |
| Hash32 Span | 5.05 GB/s |
| Hash64 Span | 8.92 GB/s |
| Hash32 Stream | 3.22 GB/s |
| Hash64 Stream | 4.81 GB/s |
| Method | Platform | Language | 1KB Time | 1MB Time | 1GB Time | Speed | Difference |
|---|---|---|---|---|---|---|---|
| Hash32 | x64 | C# | 185.1 ns | 170.6 us | 193.6 ms | 5.16 GB/s | 1.4 % |
| Hash32 | x64 | C | 183.5 ns | 170.1 us | 190.8 ms | 5.24 GB/s | 1.4 % |
| Hash64 | x64 | C# | 117.3 ns | 87.1 us | 116.9 ms | 8.55 GB/s | 2.4 % |
| Hash64 | x64 | C | 104.8 ns | 85.3 us | 114.1 ms | 8.76 GB/s | 2.4 % |
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;}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;}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));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));Made in 🔰 Ukraine with ❤️
