Skip to content

Commit 66ce394

Browse files
authored
feat: ignore no benchmark commit (#12)
1 parent 83247a0 commit 66ce394

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

main.go

+22-11
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,23 @@ func run(c config) error {
135135
var ratios []result
136136
var rows [][]string
137137
for benchName, headBenchmarks := range headSet {
138+
var prevBench, headBench *parse.Benchmark
139+
140+
if len(headBenchmarks) > 0 {
141+
headBench = headBenchmarks[0]
142+
}
143+
rows = append(rows, generateRow("HEAD", headBench))
144+
138145
prevBenchmarks, ok := prevSet[benchName]
139146
if !ok {
147+
rows = append(rows, []string{benchName, c.base, "-", "-"})
140148
continue
141149
}
142-
if len(headBenchmarks) == 0 || len(prevBenchmarks) == 0 {
143-
continue
150+
151+
if len(prevBenchmarks) > 0 {
152+
prevBench = prevBenchmarks[0]
144153
}
145-
prevBench := prevBenchmarks[0]
146-
headBench := headBenchmarks[0]
154+
rows = append(rows, generateRow(c.base, prevBench))
147155

148156
var ratioNsPerOp float64
149157
if prevBench.NsPerOp != 0 {
@@ -155,9 +163,6 @@ func run(c config) error {
155163
ratioAllocedBytesPerOp = (float64(headBench.AllocedBytesPerOp) - float64(prevBench.AllocedBytesPerOp)) / float64(prevBench.AllocedBytesPerOp)
156164
}
157165

158-
rows = append(rows, generateRow("HEAD", headBench))
159-
rows = append(rows, generateRow("HEAD@{1}", prevBench))
160-
161166
ratios = append(ratios, result{
162167
Name: benchName,
163168
RatioNsPerOp: ratioNsPerOp,
@@ -177,9 +182,17 @@ func run(c config) error {
177182
return nil
178183
}
179184

180-
func runBenchmark(cmd string, args []string) (parse.Set, error) {
181-
out, err := exec.Command(cmd, args...).Output()
185+
func runBenchmark(cmdStr string, args []string) (parse.Set, error) {
186+
var stderr bytes.Buffer
187+
cmd := exec.Command(cmdStr, args...)
188+
cmd.Stderr = &stderr
189+
190+
out, err := cmd.Output()
182191
if err != nil {
192+
if strings.HasSuffix(strings.TrimSpace(stderr.String()), "no packages to test") {
193+
return parse.Set{}, nil
194+
}
195+
log.Println(stderr.String())
183196
return nil, xerrors.Errorf("failed to run '%s %s' command: %w", cmd, strings.Join(args, " "), err)
184197
}
185198

@@ -274,10 +287,8 @@ func whichScoreToCompare(c []string) comparedScore {
274287
for _, cc := range c {
275288
switch cc {
276289
case "ns/op":
277-
fmt.Println("cpu")
278290
comparedScore.nsPerOp = true
279291
case "B/op":
280-
fmt.Println("memory")
281292
comparedScore.allocedBytesPerOp = true
282293
}
283294
}

0 commit comments

Comments
 (0)