~kb/wyhash

Fast, simple hashing and PRNG for modern processors.
Simplify output for UInt's
Fix incorrect rand_int output
Fix spelling in comments

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~kb/wyhash
read/write
git@git.sr.ht:~kb/wyhash

You can also use your local clone with git send-email.

#wyhash

WIP warning - not recommended for any real-world use.

Exceptionally fast and beautifully simple non-cryptographically secure hashing function and psuedo-random number generator for modern processors.

This is a native crystal implementation of wyhash.

Paper (pdf) with further background.

#Performance

Comparisons below against cystal-lang's current PRNG (PCG32).

> crystal run benchmark/perf.cr --release

#next_u (direct PRNG cycle output)
 pcg32 440.63M (  2.27ns) (± 1.38%)  0.0B/op   1.40x slower
wyrand 615.84M (  1.62ns) (± 1.71%)  0.0B/op         fastest

UInt32 (native for PCG32)
 pcg32 440.51M (  2.27ns) (± 1.15%)  0.0B/op   1.40x slower
wyrand 614.72M (  1.63ns) (± 1.31%)  0.0B/op         fastest

UInt64 (native for wyrand)
 pcg32  59.52M ( 16.80ns) (± 0.96%)  0.0B/op  10.12x slower
wyrand 602.20M (  1.66ns) (± 6.02%)  0.0B/op         fastest

Random bytes (10MB)
 pcg32  53.74  ( 18.61ms) (±11.09%)  10.0MB/op 2.25x slower
wyrand 120.78  (  8.28ms) (± 6.45%)  10.0MB/op       fastest

UInt8 (1..n)
 pcg32 170.91M (  5.85ns) (± 1.17%)  0.0B/op   2.57x slower
wyrand 438.72M (  2.28ns) (± 2.38%)  0.0B/op         fastest

UInt16 (1..n)
 pcg32 204.95M (  4.88ns) (± 0.93%)  0.0B/op   2.11x slower
wyrand 432.88M (  2.31ns) (± 4.26%)  0.0B/op         fastest

UInt32 (1..n)
 pcg32 125.08M (  7.99ns) (± 0.91%)  0.0B/op   3.44x slower
wyrand 430.53M (  2.32ns) (± 6.82%)  0.0B/op         fastest

UInt64 (1..n)
 pcg32  48.72M ( 20.52ns) (± 0.49%)  0.0B/op  12.62x slower
wyrand 614.89M (  1.63ns) (± 0.88%)  0.0B/op         fastest
> crystal run benchmark/gen.cr --release
 user     system      total        real
:pcg32    18.859614   6.215003   25.074617 (  46.954726)
:wyrand   8.027272    6.257800   14.285072 (  43.712943)


> ent pcg32.out
Entropy = 8.000000 bits per byte.

Optimum compression would reduce the size
of this 10737418240 byte file by 0 percent.

Chi square distribution for 10737418240 samples is 262.41, and randomly
would exceed this value 36.15 percent of the times.

Arithmetic mean value of data bytes is 127.5001 (127.5 = random).
Monte Carlo value for Pi is 3.141557000 (error 0.00 percent).
Serial correlation coefficient is -0.000012 (totally uncorrelated = 0.0).


> ent wyrand.out
Entropy = 8.000000 bits per byte.

Optimum compression would reduce the size
of this 10737418240 byte file by 0 percent.

Chi square distribution for 10737418240 samples is 231.31, and randomly
would exceed this value 85.40 percent of the times.

Arithmetic mean value of data bytes is 127.5000 (127.5 = random).
Monte Carlo value for Pi is 3.141572366 (error 0.00 percent).
Serial correlation coefficient is 0.000002 (totally uncorrelated = 0.0).

A comprehensive set of algorithmic benchmarks and comparisons to other PRNG's is availble externally.