WyHash 1.0.4

.NET Core 3.0 .NET Standard 2.0 .NET Framework 4.6.2
dotnet add package WyHash --version 1.0.4
NuGet\Install-Package WyHash -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WyHash" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WyHash --version 1.0.4
#r "nuget: WyHash, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WyHash as a Cake Addin
#addin nuget:?package=WyHash&version=1.0.4

// Install WyHash as a Cake Tool
#tool nuget:?package=WyHash&version=1.0.4


Zero-allocation C# implementation of Wang Yi's 64-bit wyhash hash algorithm and wyrand PRNG.

wyhash is an extremely fast, portable hashing algorithm, and passes all of the SMHasher tests (which evaluates collision, dispersion and randomness qualities of hash functions).

Note wyhash-dotnet currently implements wyhash v1. v2 will be implemented once considered "stable".

Getting Started

Install the WyHash package from NuGet:

Install-Package WyHash

WyHash implements HashAlgorithm, so can be integrated into existing projects easily:

var seed = 42;
var hasher = WyHash64.Create(seed);

var result = hasher.ComputeHash(myData);

A common use case is getting the resulting hash as a 64-bit unsigned integer (ulong), so a static convenience method is also provided:

// Note that if no seed is specified, it default to 0
var seed = 42;
var result = WyHash64.ComputeHash64(myData, seed);

The wyrand PRNG is also implemented:

var rng = new WyRng(42);

// Generate pseudorandom values
ulong a64BitVal = rng.NextLong();
uint a32BitVal = rng.Next();

// Fill a buffer with pseudorandom bytes
var buffer = new byte[256];

// Span is also supported
Span<byte> spanBuffer = stackalloc byte[128];

Performance & Future Work

Note wyhash-dotnet currently implements wyhash v1. v2 will be implemented once considered "stable".

Future improvements include support for Span and incremental hashing (useful for hashing streams).

At present (July 2019), wyhash is the fastest algorithm in the SMHasher benchmark.

On a dev laptop with 64GB RAM and an Intel Xeon CPU E3-1545M v5 2.90GHz CPU, this implementation can process data at a rate of around 5.5GB/s on .NET Core 3, or 3.3GB/s on .NET Core 2 or the .NET Framework - this is very fast.

The reason for the performance improvement on .NET Core 3 is that it supports hardware intrinsics, and wyhash-dotnet uses the BMI2 MULX instruction to achieve faster 64-bit integer multiplication (on systems where BMI2 is available). Support for intrinsics won't make it into the .NET Framework, but will also be in the newly announced .NET 5.

Note that PInvokeing into a native DLL built using the reference C code (see the WyHash.Native project) achieves around 10.8GB/s (more or less RAM SPEED), so there is still work to do to bridge the performance gap between C# and native - I'm very much open to suggestions here!

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on WyHash:

Package Downloads

This package contains the full-stack build for HQ.io.


TypeKitchen is a small library for fast meta-programming in .NET.


TypeKitchen is a small library for fast meta-programming in .NET.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 79,763 8/12/2019
1.0.3 18,631 7/23/2019
1.0.2 31,000 5/7/2019
1.0.1 915 4/23/2019
1.0.0 474 4/18/2019