VOOZH about

URL: https://www.nuget.org/packages/WyHash/

⇱ NuGet Gallery | WyHash 1.0.5




WyHash 1.0.5

dotnet add package WyHash --version 1.0.5
 
 
NuGet\Install-Package WyHash -Version 1.0.5
 
 
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.5" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WyHash" Version="1.0.5" />
 
Directory.Packages.props
<PackageReference Include="WyHash" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WyHash --version 1.0.5
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: WyHash, 1.0.5"
 
 
#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.
#:package WyHash@1.0.5
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WyHash&version=1.0.5
 
Install as a Cake Addin
#tool nuget:?package=WyHash&version=1.0.5
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

wyhash-dotnet

👁 NuGet
👁 Build Status

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];
rng.NextBytes(buffer);

// Span is also supported
Span<byte> spanBuffer = stackalloc byte[128];
rng.NextBytes(spanBuffer);

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!

Latest benchmarks (DataSize is the size of data hashed, in bytes):


BenchmarkDotNet=v0.13.5, OS=Windows 10 (10.0.19045.3086/22H2/2022Update)
AMD Ryzen 5 2600, 1 CPU, 12 logical and 6 physical cores
.NET SDK=7.0.107
 [Host] : .NET 6.0.18 (6.0.1823.26907), X64 RyuJIT AVX2
 ShortRun-.NET 6.0 : .NET 6.0.18 (6.0.1823.26907), X64 RyuJIT AVX2

Job=ShortRun-.NET 6.0 Runtime=.NET 6.0 IterationCount=3 
LaunchCount=1 WarmupCount=3 

Method DataSize Mean Error StdDev Min Max Ratio Rank Allocated Alloc Ratio
TestXxHash 100 17.77 ns 1.179 ns 0.065 ns 17.71 ns 17.84 ns 0.97 2 - NA
TestXxHashNative 100 21.89 ns 4.087 ns 0.224 ns 21.75 ns 22.14 ns 1.19 4 - NA
TestWyHashNative 100 14.58 ns 1.336 ns 0.073 ns 14.53 ns 14.67 ns 0.79 1 - NA
TestWyHash 100 18.40 ns 2.422 ns 0.133 ns 18.30 ns 18.55 ns 1.00 3 - NA
TestXxHash 1024 89.38 ns 10.387 ns 0.569 ns 88.95 ns 90.02 ns 0.73 3 - NA
TestXxHashNative 1024 81.17 ns 3.474 ns 0.190 ns 80.98 ns 81.36 ns 0.67 2 - NA
TestWyHashNative 1024 64.38 ns 2.001 ns 0.110 ns 64.27 ns 64.49 ns 0.53 1 - NA
TestWyHash 1024 121.77 ns 23.792 ns 1.304 ns 120.53 ns 123.13 ns 1.00 4 - NA
Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 is compatible.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net461 net461 was computed.  net462 net462 is compatible.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on WyHash:

Package Downloads
HQ

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

TypeKitchen.Reflection

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

TypeKitchen.Differencing

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.5 12,953 6/16/2023
1.0.4 173,443 8/12/2019
1.0.3 54,540 7/23/2019
1.0.2 94,826 5/7/2019
1.0.1 1,259 4/23/2019
1.0.0 861 4/18/2019