MCPcopy
hub / github.com/uber-go/zap / getBenchmarkRow

Function getBenchmarkRow

internal/readme/readme.go:130–170  ·  view source on GitHub ↗
(
	input []string, benchmarkName string, libraryName string, baseline *benchmarkRow,
)

Source from the content-addressed store, hash-verified

128}
129
130func getBenchmarkRow(
131 input []string, benchmarkName string, libraryName string, baseline *benchmarkRow,
132) (*benchmarkRow, error) {
133 line, err := findUniqueSubstring(input, fmt.Sprintf("%s/%s-", benchmarkName, libraryName))
134 if err != nil {
135 return nil, err
136 }
137 if line == "" {
138 return nil, nil
139 }
140 split := strings.Split(line, "\t")
141 if len(split) < 5 {
142 return nil, fmt.Errorf("unknown benchmark line: %s", line)
143 }
144 duration, err := time.ParseDuration(strings.ReplaceAll(strings.TrimSuffix(strings.TrimSpace(split[2]), "/op"), " ", ""))
145 if err != nil {
146 return nil, err
147 }
148 allocatedBytes, err := strconv.Atoi(strings.TrimSuffix(strings.TrimSpace(split[3]), " B/op"))
149 if err != nil {
150 return nil, err
151 }
152 allocatedObjects, err := strconv.Atoi(strings.TrimSuffix(strings.TrimSpace(split[4]), " allocs/op"))
153 if err != nil {
154 return nil, err
155 }
156 r := &benchmarkRow{
157 Name: libraryNameToMarkdownName[libraryName],
158 Time: duration,
159 AllocatedBytes: allocatedBytes,
160 AllocatedObjects: allocatedObjects,
161 }
162
163 if baseline != nil {
164 r.ZapTime = baseline.Time
165 r.ZapAllocatedBytes = baseline.AllocatedBytes
166 r.ZapAllocatedObjects = baseline.AllocatedObjects
167 }
168
169 return r, nil
170}
171
172func findUniqueSubstring(input []string, substring string) (string, error) {
173 var output string

Callers 1

getBenchmarkRowsFunction · 0.85

Calls 2

findUniqueSubstringFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected