Improve Error.Error() performance
[go-signalcontext.git] / error_test.go
index eb347ef..dc90e0e 100644 (file)
@@ -11,3 +11,12 @@ func TestError(t *testing.T) {
        assert.EqualError(t, Error{os.Interrupt},
                "received signal: "+os.Interrupt.String())
 }
+
+func BenchmarkError(b *testing.B) {
+       expected := "received signal: " + os.Interrupt.String()
+       for i := 0; i < b.N; i++ {
+               if s := (Error{os.Interrupt}).String(); s != expected {
+                       b.Fatalf("expected %s, got %s", s, expected)
+               }
+       }
+}