Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Extremely fast MurmurHash implementation with zero heap allocations

License

NotificationsYou must be signed in to change notification settings

odinmillion/MurmurHash.Net

Repository files navigation

NuGetBuild StatusLicense

Extremely fast MurmurHash3 implementation with zero heap allocations

This is a fork of theSystem.Data.HashFunction.MurmurHash.

Differences

  • Faster (zero heap allocations via Spans, reduced class inheritance, bytes to uint conversion optimisations)
  • Only 32-bit output hash value. Maybe 128-bit will be supported in the future. But you can implement it by yourself and send me PR :)

Installation

This project is available as aNuGet package

Example

Some code 1. You can use traditional byte[]

uinthash=MurmurHash3.Hash32(bytes:newbyte[]{1,2,3},seed:123456U);Console.WriteLine(hash);

Output 1

3800434721

Some code 2. State-of-the-art Span<byte> and ReadOnlySpan<byte> also supported

ReadOnlySpan<byte>span= ...uint hash=MurmurHash3.Hash32(bytes:span,seed:123456U);

Benchmarks

// * Summary *BenchmarkDotNet=v0.12.0,OS=macOS Mojave 10.14.6 (18G103) [Darwin 18.7.0]Intel Core i7-7660U CPU 2.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores.NET CoreSDK=3.1.100  [Host]     : .NET Core 3.1.0 (CoreCLR 4.700.19.56402, CoreFX 4.700.19.56404), X64 RyuJIT  DefaultJob : .NET Core 3.1.0 (CoreCLR 4.700.19.56402, CoreFX 4.700.19.56404), X64 RyuJIT

Byte[] to uint

MethodMeanStdDevRatioRatioSDGen 0Allocated
CRC3240.73 us0.696 us3.320.06--
XxHash197.13 us10.995 us15.650.6287.8906184000 B
MurMurHashByDarrenkopp51.46 us3.469 us4.040.1615.319832000 B
Blake2B91.83 us3.949 us7.570.417.568416000 B
MurMurHashNet12.28 us0.122 us1.000.00--

String to uint

MethodMeanStdDevRatioRatioSDGen 0Allocated
CRC3265.63 us1.385 us3.000.0815.258832000 B
XxHash228.36 us21.086 us9.520.28103.2715216000 B
MurMurHashByDarrenkopp77.14 us2.490 us3.530.1530.639664000 B
Blake2B119.69 us2.443 us5.460.1822.949248000 B
MurMurHashNet21.91 us0.364 us1.000.00--

Legend


[8]ページ先頭

©2009-2025 Movatter.jp