aboutsummaryrefslogtreecommitdiff
path: root/src/strings
diff options
context:
space:
mode:
Diffstat (limited to 'src/strings')
-rw-r--r--src/strings/strings_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/strings/strings_test.go b/src/strings/strings_test.go
index 7bb81ef3ca..ee0c260753 100644
--- a/src/strings/strings_test.go
+++ b/src/strings/strings_test.go
@@ -569,6 +569,35 @@ func TestTrim(t *testing.T) {
}
}
+func BenchmarkTrim(b *testing.B) {
+ b.ReportAllocs()
+
+ for i := 0; i < b.N; i++ {
+ for _, tc := range trimTests {
+ name := tc.f
+ var f func(string, string) string
+ switch name {
+ case "Trim":
+ f = Trim
+ case "TrimLeft":
+ f = TrimLeft
+ case "TrimRight":
+ f = TrimRight
+ case "TrimPrefix":
+ f = TrimPrefix
+ case "TrimSuffix":
+ f = TrimSuffix
+ default:
+ b.Errorf("Undefined trim function %s", name)
+ }
+ actual := f(tc.in, tc.arg)
+ if actual != tc.out {
+ b.Errorf("%s(%q, %q) = %q; want %q", name, tc.in, tc.arg, actual, tc.out)
+ }
+ }
+ }
+}
+
type predicate struct {
f func(rune) bool
name string