Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions perfdata/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ func (l PerfdataList) String() string {
var out strings.Builder

for _, p := range l {
if len(out.String()) > 0 {
out.WriteString(" ")
}

out.WriteString(" ")
out.WriteString(p.String())
}

return out.String()
return strings.Trim(out.String(), " ")
}

// Add a Perfdata to the list
Expand Down
13 changes: 13 additions & 0 deletions perfdata/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,16 @@ func TestPerfdataListFormating(t *testing.T) {

assert.Equal(t, "test1=23 test2=42", list.String())
}

func BenchmarkPerfdataListFormating(b *testing.B) {
b.ReportAllocs()

list := PerfdataList{}
list.Add(&Perfdata{Label: "test1", Value: 23})
list.Add(&Perfdata{Label: "test2", Value: 42})

for i := 0; i < b.N; i++ {
l := list.String()
_ = l
}
}
15 changes: 15 additions & 0 deletions result/worst_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,18 @@ func TestWorstState(t *testing.T) {
assert.Equal(t, 3, WorstState(-1))
assert.Equal(t, 3, WorstState(4))
}

func BenchmarkWorstState(b *testing.B) {
b.ReportAllocs()

// Initialize slice for benchmarking
states := make([]int, 0, 100)
for i := 0; i < 100; i++ {
states = append(states, i%4)
}

for i := 0; i < b.N; i++ {
s := WorstState(states...)
_ = s
}
}
6 changes: 1 addition & 5 deletions threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,5 @@ func BoundaryToString(value float64) (s string) {

// FormatFloat returns a string representation of floats, avoiding scientific notation and removes trailing zeros.
func FormatFloat(value float64) string {
s := fmt.Sprintf("%.3f", value)
s = strings.TrimRight(s, "0") // remove trailing 0
s = strings.TrimRight(s, ".") // remove trailing dot

return s
return strings.TrimRight(strings.TrimRight(fmt.Sprintf("%.3f", value), "0"), ".") // remove trailing 0 and trailing dot
}