github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/examples/trace_logging/main_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  	"github.com/v2pro/plz/countlog"
     6  )
     7  
     8  func Benchmark_trace_call(b *testing.B) {
     9  	for i := 0; i < b.N; i++ {
    10  		countlog.TraceCall("callee!doSomething", nil, "expensive", "hello")
    11  	}
    12  }
    13  
    14  func Benchmark_expand(b *testing.B) {
    15  	countlog.SetMinLevel(countlog.LevelInfo)
    16  	for i := 0; i < b.N; i++ {
    17  		countlog.Debug("event!some event", "expensive", func() interface{} {
    18  			return make([]byte, 1024*1024*1024)
    19  		})
    20  	}
    21  }
    22  
    23  func Benchmark_no_expand(b *testing.B) {
    24  	countlog.SetMinLevel(countlog.LevelInfo)
    25  	for i := 0; i < b.N; i++ {
    26  		countlog.Debug("event!some event", "expensive", "hello")
    27  	}
    28  }
    29  
    30  var v1 = "v1"
    31  var v2 = "v2"
    32  var v3 = "v3"
    33  var v4 = "v4"
    34  var v5 = "v5"
    35  
    36  func Benchmark_fixed_arg(b *testing.B) {
    37  	countlog.MinLevel = countlog.LevelInfo
    38  	b.ReportAllocs()
    39  	for i := 0; i < b.N; i++ {
    40  		//if countlog.ShouldLog(countlog.LevelTrace) {
    41  		//
    42  		//}
    43  		countlog.TraceCall5("callee!someThing", nil,
    44  			"k1", v1,
    45  			"k2", v2,
    46  			"k3", v3,
    47  			"k4", v4,
    48  			"k5", v5)
    49  	}
    50  }