tlog.app/go/tlog@v0.23.1/tlz_test.go (about) 1 package tlog_test 2 3 import ( 4 "io" 5 "testing" 6 7 "tlog.app/go/eazy" 8 "tlog.app/go/tlog" 9 "tlog.app/go/tlog/tlio" 10 ) 11 12 func BenchmarkLogCompressOneline(b *testing.B) { 13 b.ReportAllocs() 14 15 var full, small tlio.CountingIODiscard 16 w := eazy.NewWriter(&small, 128*1024, 1024) 17 18 l := tlog.New(io.MultiWriter(&full, w)) 19 tr := l.Start("span_name") 20 21 types := []string{"type_a", "value_b", "qweqew", "asdads"} 22 23 for i := 0; i < b.N; i++ { 24 // tr := l.Start("span_name") 25 tr.Printw("some example message", "i", i, "type", types[i%len(types)]) 26 // tr.Finish() 27 } 28 29 b.SetBytes(full.Bytes.Load() / int64(b.N)) 30 b.ReportMetric(float64(full.Bytes.Load())/float64(small.Bytes.Load()), "ratio") 31 } 32 33 func BenchmarkLogCompressOnelineText(b *testing.B) { 34 b.ReportAllocs() 35 36 var full, small tlio.CountingIODiscard 37 w := eazy.NewWriter(&small, 128*1024, 1024) 38 cw := tlog.NewConsoleWriter(io.MultiWriter(&full, w), tlog.LstdFlags) 39 40 l := tlog.New(cw) 41 tr := l.Start("span_name") 42 43 types := []string{"type_a", "value_b", "qweqew", "asdads"} 44 45 for i := 0; i < b.N; i++ { 46 // tr := l.Start("span_name") 47 tr.Printw("some example message", "i", i, "type", types[i%len(types)]) 48 // tr.Finish() 49 } 50 51 b.SetBytes(full.Bytes.Load() / int64(b.N)) 52 b.ReportMetric(float64(full.Bytes.Load())/float64(small.Bytes.Load()), "ratio") 53 }