1
2
3
4
5 package main
6
7 import (
8 "bytes"
9 "fmt"
10 "os"
11 "runtime"
12 "time"
13 )
14
15
16
17
18 func startBench() func() {
19 start := time.Now()
20 return func() {
21 wall := time.Since(start)
22 var ms runtime.MemStats
23 runtime.ReadMemStats(&ms)
24
25 var buf bytes.Buffer
26 fmt.Fprintf(&buf, "BenchmarkSimdgen/target=%s", *FlagArch)
27
28 if procs := runtime.GOMAXPROCS(0); procs != 1 {
29 fmt.Fprintf(&buf, "-%d", procs)
30 }
31 fmt.Fprintf(&buf, " 1 %d ns/op", wall.Nanoseconds())
32 if t, ok := cpuTime(); ok {
33 fmt.Fprintf(&buf, " %d cpu-ns/op", t.Nanoseconds())
34 }
35 fmt.Fprintf(&buf, " %d B/op %d allocs/op\n", ms.TotalAlloc, ms.Mallocs)
36 os.Stderr.Write(buf.Bytes())
37 }
38 }
39
View as plain text