Skip to content

Commit 4707e11

Browse files
committed
Use tabwriter to align table columns in output
1 parent 64a373f commit 4707e11

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

internal/cmd/perfcomp/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"math"
1818
"os"
1919
"strings"
20+
"text/tabwriter"
2021
"time"
2122

2223
"go.mongodb.org/mongo-driver/v2/bson"
@@ -303,15 +304,19 @@ func generatePRComment(energyStats []*EnergyStats, version string) string {
303304
var comment strings.Builder
304305
comment.WriteString("# 👋GoDriver Performance\n")
305306
fmt.Fprintf(&comment, "The following benchmark tests for version %s had statistically significant changes (i.e., |z-score| > 1.96):\n", version)
306-
comment.WriteString("| Benchmark | Measurement | H-Score | Z-Score | % Change | Stable Reg | Patch Value |\n| --- | --- | --- | --- | --- | --- | --- |\n")
307+
308+
w := tabwriter.NewWriter(&comment, 0, 0, 1, ' ', 0)
309+
fmt.Fprintln(w, "| Benchmark\t| Measurement\t| H-Score\t| Z-Score\t| % Change\t| Stable Reg\t| Patch Value\t|")
310+
fmt.Fprintln(w, "| ---------\t| -----------\t| -------\t| -------\t| --------\t| ----------\t| -----------\t|")
307311

308312
var testCount int64
309313
for _, es := range energyStats {
310314
if math.Abs(es.ZScore) > 1.96 {
311315
testCount += 1
312-
fmt.Fprintf(&comment, "| %s | %s | %.4f | %.4f | %.4f | Avg: %.4f, Med: %.4f, Stdev: %.4f | %.4f |\n", es.Benchmark, es.Measurement, es.HScore, es.ZScore, es.PercentChange, es.StableRegion.Mean, es.StableRegion.Median, es.StableRegion.Std, es.MeasurementVal)
316+
fmt.Fprintf(w, "| %s\t| %s\t| %.4f\t| %.4f\t| %.4f\t| Avg: %.4f, Med: %.4f, Stdev: %.4f\t| %.4f\t|\n", es.Benchmark, es.Measurement, es.HScore, es.ZScore, es.PercentChange, es.StableRegion.Mean, es.StableRegion.Median, es.StableRegion.Std, es.MeasurementVal)
313317
}
314318
}
319+
w.Flush()
315320

316321
if testCount == 0 {
317322
comment.Reset()

0 commit comments

Comments
 (0)