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
parent 77891cedae
commit 59befed8ee

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: