Merge pull request #2395 from calmh/printhashrate

Print the single thread hash performance at startup
This commit is contained in:
Audrius Butkevicius 2015-10-20 08:10:52 +01:00
commit a7e95922c1
2 changed files with 30 additions and 11 deletions

View File

@ -516,6 +516,7 @@ func syncthingMain() {
l.Infoln(LongVersion)
l.Infoln("My ID:", myID)
printHashRate()
// Emit the Starting event, now that we know who we are.
@ -836,6 +837,22 @@ func syncthingMain() {
os.Exit(code)
}
// printHashRate prints the hashing performance in MB/s, formatting it with
// appropriate precision for the value, i.e. 182 MB/s, 18 MB/s, 1.8 MB/s, 0.18
// MB/s.
func printHashRate() {
hashRate := cpuBench(3, 100*time.Millisecond)
decimals := 0
if hashRate < 1 {
decimals = 2
} else if hashRate < 10 {
decimals = 1
}
l.Infof("Single thread hash performance is ~%.*f MB/s", decimals, hashRate)
}
func loadConfig(cfgFile string) (*config.Wrapper, string, error) {
info, err := os.Stat(cfgFile)
if err != nil {

View File

@ -112,15 +112,7 @@ func reportData(cfg *config.Wrapper, m *model.Model) map[string]interface{} {
var mem runtime.MemStats
runtime.ReadMemStats(&mem)
res["memoryUsageMiB"] = (mem.Sys - mem.HeapReleased) / 1024 / 1024
var perf float64
for i := 0; i < 5; i++ {
p := cpuBench()
if p > perf {
perf = p
}
}
res["sha256Perf"] = perf
res["sha256Perf"] = cpuBench(5, 125*time.Millisecond)
bytes, err := memorySize()
if err == nil {
@ -301,7 +293,17 @@ func (s *usageReportingService) Stop() {
}
// cpuBench returns CPU performance as a measure of single threaded SHA-256 MiB/s
func cpuBench() float64 {
func cpuBench(iterations int, duration time.Duration) float64 {
var perf float64
for i := 0; i < iterations; i++ {
if v := cpuBenchOnce(duration); v > perf {
perf = v
}
}
return perf
}
func cpuBenchOnce(duration time.Duration) float64 {
chunkSize := 100 * 1 << 10
h := sha256.New()
bs := make([]byte, chunkSize)
@ -309,7 +311,7 @@ func cpuBench() float64 {
t0 := time.Now()
b := 0
for time.Since(t0) < 125*time.Millisecond {
for time.Since(t0) < duration {
h.Write(bs)
b += chunkSize
}