You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
727 B

8 years ago
8 years ago
  1. package log_test
  2. import (
  3. "io/ioutil"
  4. "testing"
  5. "github.com/tendermint/tmlibs/log"
  6. )
  7. func BenchmarkTMLoggerSimple(b *testing.B) {
  8. benchmarkRunner(b, log.NewTMLogger(ioutil.Discard), baseInfoMessage)
  9. }
  10. func BenchmarkTMLoggerContextual(b *testing.B) {
  11. benchmarkRunner(b, log.NewTMLogger(ioutil.Discard), withInfoMessage)
  12. }
  13. func benchmarkRunner(b *testing.B, logger log.Logger, f func(log.Logger)) {
  14. lc := logger.With("common_key", "common_value")
  15. b.ReportAllocs()
  16. b.ResetTimer()
  17. for i := 0; i < b.N; i++ {
  18. f(lc)
  19. }
  20. }
  21. var (
  22. baseInfoMessage = func(logger log.Logger) { logger.Info("foo_message", "foo_key", "foo_value") }
  23. withInfoMessage = func(logger log.Logger) { logger.With("a", "b").Info("c", "d", "f") }
  24. )