Skip to content

Commit e2c5e28

Browse files
committed
fix(lint): address golines and modernize on benchstat and RDB benchmarks.
1 parent 3169639 commit e2c5e28

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

cmd/scw-benchstat/main.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"os/exec"
1212
"path/filepath"
13+
"slices"
1314
"strconv"
1415
"strings"
1516
"time"
@@ -310,8 +311,9 @@ func checkForRegressions(cfg config, csvOutput string) error {
310311
benchName := record[nameIdx]
311312

312313
// Check time/op regression
313-
if contains(cfg.failMetrics, "time/op") && oldTimeIdx != -1 && newTimeIdx != -1 {
314-
if regression := checkMetricRegression(record, oldTimeIdx, newTimeIdx, cfg.threshold); regression != "" {
314+
if slices.Contains(cfg.failMetrics, "time/op") && oldTimeIdx != -1 && newTimeIdx != -1 {
315+
regression := checkMetricRegression(record, oldTimeIdx, newTimeIdx, cfg.threshold)
316+
if regression != "" {
315317
regressions = append(
316318
regressions,
317319
fmt.Sprintf("%s: time/op %s", benchName, regression),
@@ -320,15 +322,17 @@ func checkForRegressions(cfg config, csvOutput string) error {
320322
}
321323

322324
// Check B/op regression
323-
if contains(cfg.failMetrics, "B/op") && oldBytesIdx != -1 && newBytesIdx != -1 {
324-
if regression := checkMetricRegression(record, oldBytesIdx, newBytesIdx, cfg.threshold); regression != "" {
325+
if slices.Contains(cfg.failMetrics, "B/op") && oldBytesIdx != -1 && newBytesIdx != -1 {
326+
regression := checkMetricRegression(record, oldBytesIdx, newBytesIdx, cfg.threshold)
327+
if regression != "" {
325328
regressions = append(regressions, fmt.Sprintf("%s: B/op %s", benchName, regression))
326329
}
327330
}
328331

329332
// Check allocs/op regression
330-
if contains(cfg.failMetrics, "allocs/op") && oldAllocsIdx != -1 && newAllocsIdx != -1 {
331-
if regression := checkMetricRegression(record, oldAllocsIdx, newAllocsIdx, cfg.threshold); regression != "" {
333+
if slices.Contains(cfg.failMetrics, "allocs/op") && oldAllocsIdx != -1 && newAllocsIdx != -1 {
334+
regression := checkMetricRegression(record, oldAllocsIdx, newAllocsIdx, cfg.threshold)
335+
if regression != "" {
332336
regressions = append(
333337
regressions,
334338
fmt.Sprintf("%s: allocs/op %s", benchName, regression),
@@ -405,13 +409,3 @@ func parseMetricValue(s string) (float64, error) {
405409

406410
return strconv.ParseFloat(s, 64)
407411
}
408-
409-
func contains(slice []string, item string) bool {
410-
for _, s := range slice {
411-
if s == item {
412-
return true
413-
}
414-
}
415-
416-
return false
417-
}

internal/namespaces/rdb/v1/custom_benchmark_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"fmt"
88
"net/http"
99
"os"
10-
"sort"
10+
"slices"
1111
"strings"
1212
"testing"
1313
"time"
@@ -134,9 +134,7 @@ func (s *benchmarkStats) report(b *testing.B) {
134134
return
135135
}
136136

137-
sort.Slice(s.timings, func(i, j int) bool {
138-
return s.timings[i] < s.timings[j]
139-
})
137+
slices.Sort(s.timings)
140138

141139
minVal := s.timings[0]
142140
maxVal := s.timings[len(s.timings)-1]

0 commit comments

Comments
 (0)