log: avoid stack lookups when not needed/used (#28069)

Avoids the somewhat expensive stack.Caller invocation by checking if it is needed
This commit is contained in:
Martin Holst Swende
2023-09-07 08:48:49 -04:00
committed by GitHub
parent c60f7dd08d
commit a8d7201ec5
5 changed files with 99 additions and 5 deletions
+12
View File
@@ -25,6 +25,7 @@ import (
"reflect"
"strings"
"testing"
"time"
)
func TestBytesConversion(t *testing.T) {
@@ -583,3 +584,14 @@ func TestAddressEIP55(t *testing.T) {
t.Fatal("Unexpected address after unmarshal")
}
}
func BenchmarkPrettyDuration(b *testing.B) {
var x = PrettyDuration(time.Duration(int64(1203123912312)))
b.Logf("Pre %s", time.Duration(x).String())
var a string
b.ResetTimer()
for i := 0; i < b.N; i++ {
a = x.String()
}
b.Logf("Post %s", a)
}