MCPcopy
hub / github.com/grafana/dskit / BenchmarkStringsCut

Function BenchmarkStringsCut

tenant/tenant_test.go:102–129  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

100}
101
102func BenchmarkStringsCut(b *testing.B) {
103 testStrings := []struct {
104 name string
105 s string
106 }{
107 {"short-no-match", "tenant-a"},
108 {"short-match", "tenant:k6"},
109 {"medium-no-match", "tenant-abcdefghijklmnop"},
110 {"medium-match-end", "tenant-abcdefghijklmnop:k6"},
111 {"long-no-match", "tenant-abcdefghijklmnopqrstuvwxyz0123456789"},
112 {"long-match-end", "tenant-abcdefghijklmnopqrstuvwxyz0123456789:k6"},
113 }
114
115 for _, ts := range testStrings {
116 b.Run("strings.Cut/"+ts.name, func(b *testing.B) {
117 s := ts.s
118 for i := 0; i < b.N; i++ {
119 _, _, _ = strings.Cut(s, ":")
120 }
121 })
122 b.Run("stringsCut/"+ts.name, func(b *testing.B) {
123 s := ts.s
124 for i := 0; i < b.N; i++ {
125 _, _, _ = stringsCut(s, ':')
126 }
127 })
128 }
129}

Callers

nothing calls this directly

Calls 2

stringsCutFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected