Repository navigation
Expand file tree
/
Copy pathtable.go
More file actions
170 lines (161 loc) · 5.2 KB
/
Copy pathtable.go
File metadata and controls
170 lines (161 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package refbench
import (
"bytes"
"fmt"
"sort"
"strings"
)
// Table renders docs/perf-table.md from a report. It is a pure function of the
// report's content, so the CI mode can check that the file has no hand edits.
func Table(r *Report) []byte {
r.Finish()
var b bytes.Buffer
b.WriteString("# Performance table\n\n")
b.WriteString("<!-- Generated by refbench from docs/perf.json. Do not edit. -->\n\n")
fmt.Fprintf(&b, "- Date: %s\n- Commit: %s\n- Go: %s\n- Machine: %s\n", r.Date, r.Commit, r.Go, r.Machine)
keys := make([]string, 0, len(r.RefVersions))
for k := range r.RefVersions {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
fmt.Fprintf(&b, "- %s: %s\n", k, r.RefVersions[k])
}
switch r.Status {
case StatusDeferred:
b.WriteString("- Timing: **deferred** (no verdict; allocation counts only)\n")
case StatusMeasured:
fmt.Fprintf(&b, "- Load (1 min) over the rounds: min %.2f, median %.2f, max %.2f; gate %.2f\n",
r.Load.Min, r.Load.Median, r.Load.Max, r.MaxLoad)
if r.Valid {
b.WriteString("- Run: valid (every round under the gate)\n")
} else {
fmt.Fprintf(&b, "- Run: **partial: %d of %d rows valid** (the others are deferred; `-perf.resume` measures only those)\n", r.ValidRows(), len(r.Rows))
}
if r.Retries > 0 {
fmt.Fprintf(&b, "- Retries: %d rounds ended above the gate and were re-run\n", r.Retries)
}
}
b.WriteString("\nns/call, median [first quartile, third quartile]; ratio = Go / reference.\n\n")
b.WriteString("| case | function | reference | Go | reference | ratio | verdict | parity | allocs |\n")
b.WriteString("|---|---|---|---:|---:|---:|---|---|---:|\n")
for _, row := range r.Rows {
goCell, refCell, ratio, verdict := "—", "—", "—", "deferred"
if len(row.Rounds) > 0 {
goCell, refCell = cell(row.Go), cell(row.Ref)
ratio = fmt.Sprintf("%.2f", row.Ratio)
verdict = row.Verdict
if !row.Valid {
verdict = "invalid"
}
}
fmt.Fprintf(&b, "| %s | `%s` | %s | %s | %s | %s | %s | %s | %g |\n",
esc(row.Name), row.Func, esc(row.Reference), goCell, refCell, ratio, verdict, row.Parity, row.Allocs)
}
if r.usesRefs() {
refsSection(&b, r)
}
return b.Bytes()
}
// refsSection is the second section of a schema 2 table: Go against every other
// reference, with the accuracy of each side. The first section is unchanged.
func refsSection(b *bytes.Buffer, r *Report) {
var ids []string
names := map[string]string{}
for _, row := range r.Rows {
for _, ref := range row.Refs {
if _, ok := names[ref.ID]; !ok {
ids = append(ids, ref.ID)
names[ref.ID] = ref.ID // the ID is unambiguous; the best column shows the name
}
}
}
sort.Strings(ids)
b.WriteString("\n## Against other references\n\n")
b.WriteString("Ratio = Go / reference, from the same rounds as the table above. Each cell: ratio (verdict, label; max ulp, coverage). The headline is Go against the fastest side, primary reference included: a reference that is faster is a defect even when it is less accurate.\n\n")
b.WriteString("| case | Go ns | Go max ulp | best | ratio vs best | label |")
for _, id := range ids {
fmt.Fprintf(b, " %s |", esc(names[id]))
}
b.WriteString("\n|---|---:|---:|---|---:|---|")
for range ids {
b.WriteString("---|")
}
b.WriteString("\n")
for _, row := range r.Rows {
if !row.usesMultiRef() {
continue
}
goNs, goUlp, best, ratio, label := "—", ulpCell(row.GoAccuracy), "—", "—", "deferred"
if len(row.Rounds) > 0 {
goNs, label = fmt.Sprintf("%.4g", row.Go.Median), row.Verdict
if row.Best != "" { // a row with accuracy but no extra reference has no headline
best, ratio, label = esc(sideName(row, row.Best)), fmt.Sprintf("%.2f", row.BestRatio), row.BestVerdict
}
if row.BestLabel != "" {
label += ", " + row.BestLabel
}
if !row.Valid {
label = "invalid"
}
}
fmt.Fprintf(b, "| %s | %s | %s | %s | %s | %s |", esc(row.Name), goNs, goUlp, best, ratio, label)
byID := map[string]RefRow{}
for _, ref := range row.Refs {
byID[ref.ID] = ref
}
for _, id := range ids {
ref, ok := byID[id]
switch {
case !ok:
b.WriteString(" — |")
case len(row.Rounds) == 0:
fmt.Fprintf(b, " deferred (%s) |", accCell(ref.Accuracy))
default:
v := ref.Verdict
if ref.Label != "" {
v += ", " + ref.Label
}
fmt.Fprintf(b, " %.2f (%s; %s) |", ref.Ratio, v, accCell(ref.Accuracy))
}
}
b.WriteString("\n")
}
}
func sideName(row Row, id string) string {
if id == SidePrimary {
return row.Reference
}
for _, ref := range row.Refs {
if ref.ID == id {
return ref.label()
}
}
return id
}
func ulpCell(a *AccResult) string {
if a == nil {
return "—"
}
return fmt.Sprintf("%.3g", float64(a.MaxULP))
}
func covCell(a *AccResult) string {
if a == nil {
return "—"
}
return fmt.Sprintf("%.0f%%", 100*a.Coverage)
}
func accCell(a *AccResult) string {
if a == nil {
return "no accuracy"
}
s := fmt.Sprintf("%.3g ulp, fin %.3g, cov %.0f%%", float64(a.MaxULP), float64(a.MaxULPFin), 100*a.Coverage)
if a.Disagree > 0 {
s += fmt.Sprintf(", %d disagree", a.Disagree)
}
return s
}
func cell(s Summary) string {
return fmt.Sprintf("%.4g [%.4g, %.4g]", s.Median, s.Q1, s.Q3)
}
func esc(s string) string { return strings.ReplaceAll(s, "|", `\|`) }