• Giovanni Bajo's avatar
    runtime: improve fastrand with a better generator · e7e4a4ff
    Giovanni Bajo authored
    The current generator is a simple LSFR, which showed strong
    correlation in higher bits, as manifested by fastrandn().
    
    Change it with xorshift64+, which is slightly more complex,
    has a larger state, but has a period of 2^64-1 and is much better
    at statistical tests. The version used here is capable of
    passing Diehard and even SmallCrush.
    
    Speed is slightly worse but is probably insignificant:
    
    name                old time/op  new time/op  delta
    Fastrand-4          0.77ns ±12%  0.91ns ±21%  +17.31%  (p=0.048 n=5+5)
    FastrandHashiter-4  13.6ns ±21%  15.2ns ±17%     ~     (p=0.160 n=6+5)
    Fastrandn/2-4       2.30ns ± 5%  2.45ns ±15%     ~     (p=0.222 n=5+5)
    Fastrandn/3-4       2.36ns ± 7%  2.45ns ± 6%     ~     (p=0.222 n=5+5)
    Fastrandn/4-4       2.33ns ± 8%  2.61ns ±30%     ~     (p=0.126 n=6+5)
    Fastrandn/5-4       2.33ns ± 5%  2.48ns ± 9%     ~     (p=0.052 n=6+5)
    
    Fixes #21806
    
    Change-Id: I013bb37b463fdfc229a7f324df8fe2da8d286f33
    Reviewed-on: https://go-review.googlesource.com/62530
    Run-TryBot: Michael Munday <mike.munday@ibm.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarKeith Randall <khr@golang.org>
    e7e4a4ff
chan_test.go 21.1 KB