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:
parent
77891cedae
commit
59befed8ee
1 changed files with 3 additions and 1 deletions
|
|
@ -188,8 +188,10 @@ proc skipRandomNumbers*(s: var Rand) =
|
||||||
|
|
||||||
proc randomSum(params: tuple[r: Rand, index: int]) {.thread.} =
|
proc randomSum(params: tuple[r: Rand, index: int]) {.thread.} =
|
||||||
var r = params.r
|
var r = params.r
|
||||||
|
var s = 0 # avoid cache thrashing
|
||||||
for i in 1..numbers:
|
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)
|
var r = initRand(2019)
|
||||||
for i in 0..<thr.len:
|
for i in 0..<thr.len:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue