cmd/syncthing: Speed up the CPU benchmark
Not the measured performance, just the wall clock time it takes to complete. The random generation was dominating.
This commit is contained in:
parent
67acef1794
commit
e14741a58c
@ -288,9 +288,13 @@ func (s *usageReportingService) Stop() {
|
|||||||
|
|
||||||
// cpuBench returns CPU performance as a measure of single threaded SHA-256 MiB/s
|
// cpuBench returns CPU performance as a measure of single threaded SHA-256 MiB/s
|
||||||
func cpuBench(iterations int, duration time.Duration, useWeakHash bool) float64 {
|
func cpuBench(iterations int, duration time.Duration, useWeakHash bool) float64 {
|
||||||
|
dataSize := 16 * protocol.BlockSize
|
||||||
|
bs := make([]byte, dataSize)
|
||||||
|
rand.Reader.Read(bs)
|
||||||
|
|
||||||
var perf float64
|
var perf float64
|
||||||
for i := 0; i < iterations; i++ {
|
for i := 0; i < iterations; i++ {
|
||||||
if v := cpuBenchOnce(duration, useWeakHash); v > perf {
|
if v := cpuBenchOnce(duration, useWeakHash, bs); v > perf {
|
||||||
perf = v
|
perf = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -300,17 +304,13 @@ func cpuBench(iterations int, duration time.Duration, useWeakHash bool) float64
|
|||||||
|
|
||||||
var blocksResult []protocol.BlockInfo // so the result is not optimized away
|
var blocksResult []protocol.BlockInfo // so the result is not optimized away
|
||||||
|
|
||||||
func cpuBenchOnce(duration time.Duration, useWeakHash bool) float64 {
|
func cpuBenchOnce(duration time.Duration, useWeakHash bool, bs []byte) float64 {
|
||||||
dataSize := 16 * protocol.BlockSize
|
|
||||||
bs := make([]byte, dataSize)
|
|
||||||
rand.Reader.Read(bs)
|
|
||||||
|
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
b := 0
|
b := 0
|
||||||
for time.Since(t0) < duration {
|
for time.Since(t0) < duration {
|
||||||
r := bytes.NewReader(bs)
|
r := bytes.NewReader(bs)
|
||||||
blocksResult, _ = scanner.Blocks(r, protocol.BlockSize, int64(dataSize), nil, useWeakHash)
|
blocksResult, _ = scanner.Blocks(r, protocol.BlockSize, int64(len(bs)), nil, useWeakHash)
|
||||||
b += dataSize
|
b += len(bs)
|
||||||
}
|
}
|
||||||
d := time.Since(t0)
|
d := time.Since(t0)
|
||||||
return float64(int(float64(b)/d.Seconds()/(1<<20)*100)) / 100
|
return float64(int(float64(b)/d.Seconds()/(1<<20)*100)) / 100
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user