func toCSV()

in benchstat/text.go [245:293]


func toCSV(t *Table, norange bool) []*textRow {
	var textRows []*textRow
	units := ""
	if len(t.Rows) > 0 && len(t.Rows[0].Metrics) > 0 {
		units = " (" + t.Rows[0].Metrics[0].Unit + ")"
	}
	switch len(t.Configs) {
	case 1:
		textRows = append(textRows, newTextRowDelta(norange, "name", t.Metric+units))
	case 2:
		textRows = append(textRows, newTextRowDelta(norange, "name", "old "+t.Metric+units, "new "+t.Metric+units, "delta"))
	default:
		rowname := "name \\ " + t.Metric
		row := newTextRowDelta(norange, rowname+units, trimCommonPathPrefix(t.Configs)...)
		textRows = append(textRows, row)
	}

	var group string

	for _, row := range t.Rows {
		if row.Group != group {
			group = row.Group
			textRows = append(textRows, newTextRow(group))
		}
		text := newTextRow(row.Benchmark)
		for _, m := range row.Metrics {
			mean := fmt.Sprintf("%.5E", m.Mean)
			diff := m.FormatDiff()
			if m.Unit == "" {
				mean = ""
				diff = ""
			}
			text.cols = append(text.cols, mean)
			if !norange {
				text.cols = append(text.cols, diff)
			}
		}
		if len(t.Configs) == 2 {
			delta := row.Delta
			text.cols = append(text.cols, delta)
			text.cols = append(text.cols, row.Note)
		}
		textRows = append(textRows, text)
	}
	for _, r := range textRows {
		r.trim()
	}
	return textRows
}