mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
lib/ur: Prevent trivial race in CPU bench
This commit is contained in:
parent
c2ea9d119d
commit
0832285d79
@ -17,6 +17,7 @@ import (
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
@ -425,8 +426,16 @@ func (*Service) String() string {
|
||||
return "ur.Service"
|
||||
}
|
||||
|
||||
var (
|
||||
blocksResult []protocol.BlockInfo // so the result is not optimized away
|
||||
blocksResultMut sync.Mutex
|
||||
)
|
||||
|
||||
// CpuBench returns CPU performance as a measure of single threaded SHA-256 MiB/s
|
||||
func CpuBench(iterations int, duration time.Duration, useWeakHash bool) float64 {
|
||||
blocksResultMut.Lock()
|
||||
defer blocksResultMut.Unlock()
|
||||
|
||||
dataSize := 16 * protocol.MinBlockSize
|
||||
bs := make([]byte, dataSize)
|
||||
rand.Reader.Read(bs)
|
||||
@ -441,8 +450,6 @@ func CpuBench(iterations int, duration time.Duration, useWeakHash bool) float64
|
||||
return perf
|
||||
}
|
||||
|
||||
var blocksResult []protocol.BlockInfo // so the result is not optimized away
|
||||
|
||||
func cpuBenchOnce(duration time.Duration, useWeakHash bool, bs []byte) float64 {
|
||||
t0 := time.Now()
|
||||
b := 0
|
||||
|
Loading…
Reference in New Issue
Block a user