prevent cache thrashing (#20129)

* prevent cache thrash

Co-authored-by: Charles Blake <cb@cblake.net>

* Update lib/pure/random.nim

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Co-authored-by: Charles Blake <cb@cblake.net>
Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
This commit is contained in:
ringabout 2022-08-02 00:06:27 +08:00 • committed by GitHub
commit 59befed8ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -188,8 +188,10 @@ proc skipRandomNumbers*(s: var Rand) =
proc randomSum(params: tuple[r: Rand, index: int]) {.thread.} =
var r = params.r
var s = 0 # avoid cache thrashing
for i in 1..numbers:
vals[params.index] += r.rand(0..10)
s += r.rand(0..10)
vals[params.index] = s
var r = initRand(2019)
for i in 0..<thr.len: