Skip to content

Repository files navigation

xxHash.st

Extremely fast non-cryptographic hash algorithm xxhash


buildcoveragenugetplatformlicense

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.

Instalation

PM> Install-Package Standart.Hash.xxHash

Benchmarks

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)

Methodx64
Hash32 Array5.05 GB/s
Hash64 Array8.92 GB/s
Hash32 Span5.05 GB/s
Hash64 Span8.92 GB/s
Hash32 Stream3.22 GB/s
Hash64 Stream4.81 GB/s

Comparison between С# and C implementation

MethodPlatformLanguage1KB Time1MB Time1GB TimeSpeedDifference
Hash32x64C#185.1 ns170.6 us193.6 ms5.16 GB/s1.4 %
Hash32x64C183.5 ns170.1 us190.8 ms5.24 GB/s1.4 %
Hash64x64C#117.3 ns87.1 us116.9 ms8.55 GB/s2.4 %
Hash64x64C104.8 ns85.3 us114.1 ms8.76 GB/s2.4 %

Api

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;}

Examples

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 ❤️

About

A pure C# implementation of xxhash algorithm

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages