-
Notifications
You must be signed in to change notification settings - Fork 4
/
bench_test.go
98 lines (82 loc) · 1.98 KB
/
bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package log
import (
"bytes"
"log"
"os"
"testing"
"github.com/inconshreveable/log15"
"github.com/juju/loggo"
"github.com/juju/loggo/loggocolor"
gologging "github.com/op/go-logging"
"github.com/sirupsen/logrus"
)
var hostname string
func init() {
var err error
hostname, err = os.Hostname()
if err != nil {
panic(err)
}
}
func BenchmarkLog15(b *testing.B) {
var buf bytes.Buffer
var logger = log15.New("test", "test")
logger.SetHandler(log15.StreamHandler(&buf, log15.LogfmtFormat()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
logger.Info("This is a test: ", hostname, nil)
}
}
func BenchmarkLogrus(b *testing.B) {
var buf bytes.Buffer
logrus.SetOutput(&buf)
b.ResetTimer()
for i := 0; i < b.N; i++ {
logrus.WithFields(logrus.Fields{
"hostname": hostname,
}).Info("This is a test: ")
}
}
func BenchmarkLoggo(b *testing.B) {
var buf bytes.Buffer
var logger = loggo.GetLogger("")
logger.SetLogLevel(loggo.INFO)
if _, err := loggo.RemoveWriter("default"); err != nil {
panic(err)
}
var writer = loggocolor.NewColorWriter(&buf)
if err := loggo.RegisterWriter("default", writer); err != nil {
panic(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
logger.Infof("This is a test: %s", hostname)
}
}
func BenchmarkGoLogging(b *testing.B) {
var buf bytes.Buffer
var logger = gologging.MustGetLogger("test")
var backend = gologging.NewLogBackend(&buf, "test", 0)
leveledBackend := gologging.AddModuleLevel(backend)
logger.SetBackend(leveledBackend)
b.ResetTimer()
for i := 0; i < b.N; i++ {
logger.Infof("This is a test: %s", hostname)
}
}
func BenchmarkThisPackage(b *testing.B) {
var buf bytes.Buffer
var logger = NewLeveledLogger(&buf, LstdFlags)
b.ResetTimer()
for i := 0; i < b.N; i++ {
logger.Printf("This is a test: %s", hostname)
}
}
func BenchmarkStdLog(b *testing.B) {
var buf bytes.Buffer
var logger = log.New(&buf, "test", log.LstdFlags)
b.ResetTimer()
for i := 0; i < b.N; i++ {
logger.Printf("This is a test: %s", hostname)
}
}