logtail: reduce allocations encoding text
import (
"context"
"testing"
+ "time"
)
func TestFastShutdown(t *testing.T) {
@@ -18,3 +19,16 @@ func TestFastShutdown(t *testing.T) {
})
l.Shutdown(ctx)
}
+
+var sink []byte
+
+func TestLoggerEncodeTextAllocs(t *testing.T) {
+ lg := &logger{timeNow: time.Now}
+ inBuf := []byte("some text to encode")
+ n := testing.AllocsPerRun(1000, func() {
+ sink = lg.encodeText(inBuf, false)
+ })
+ if int(n) != 1 {
+ t.Logf("allocs = %d; want 1", int(n))
+ }
+}
