@@ -4,15 +4,94 @@ import (
44"testing"
55)
66
7- // go test -run=benchmark -bench=. -benchtime="3s"
7+ // go test -run=benchmark -cpu=1,2,4 -benchmem -benchtime=3s -bench="ConsoleText"
8+ func BenchmarkLoggerConsoleText (b * testing.B ) {
9+ logger := NewLogger ()
10+ b .ResetTimer ()
11+ b .RunParallel (func (pb * testing.PB ) {
12+ for pb .Next () {
13+ logger .Info ("benchmark logger message" )
14+ }
15+ })
16+ }
817
9- func BenchmarkLoggerConsole ( b * testing. B ) {
10- b . ReportAllocs ()
18+ // go test -run=benchmark -cpu=1,2,4 -benchmem -benchtime=3s -bench="ConsoleAsyncText"
19+ func BenchmarkLoggerConsoleAsyncText ( b * testing. B ) {
1120logger := NewLogger ()
21+ logger .SetAsync ()
22+
1223b .ResetTimer ()
1324b .RunParallel (func (pb * testing.PB ) {
1425for pb .Next () {
1526logger .Info ("benchmark logger message" )
1627}
1728})
29+ logger .Flush ()
1830}
31+
32+ // go test -run=benchmark -cpu=1,2,4 -benchmem -benchtime=3s -bench="ConsoleJson"
33+ func BenchmarkLoggerConsoleJson (b * testing.B ) {
34+ logger := NewLogger ()
35+ logger .Detach ("console" )
36+ logger .Attach ("console" , LOGGER_LEVEL_DEBUG , & ConsoleConfig {
37+ JsonFormat : true ,
38+ })
39+ b .ResetTimer ()
40+ b .RunParallel (func (pb * testing.PB ) {
41+ for pb .Next () {
42+ logger .Info ("benchmark logger message" )
43+ }
44+ })
45+ }
46+
47+ // go test -run=benchmark -cpu=1,2,4 -benchmem -benchtime=3s -bench="FileText"
48+ func BenchmarkLoggerFileText (b * testing.B ) {
49+ logger := NewLogger ()
50+ logger .Detach ("console" )
51+ logger .Attach ("file" , LOGGER_LEVEL_DEBUG , & FileConfig {
52+ Filename :"./test.log" ,
53+ DateSlice : "d" ,
54+ })
55+ b .ResetTimer ()
56+ b .RunParallel (func (pb * testing.PB ) {
57+ for pb .Next () {
58+ logger .Info ("benchmark logger message" )
59+ }
60+ })
61+ }
62+
63+ // go test -run=benchmark -cpu=1,2,4 -benchmem -benchtime=3s -bench="AsyncText"
64+ func BenchmarkLoggerFileAsyncText (b * testing.B ) {
65+ logger := NewLogger ()
66+ logger .Detach ("console" )
67+ logger .Attach ("file" , LOGGER_LEVEL_DEBUG , & FileConfig {
68+ Filename :"./test.log" ,
69+ DateSlice : "d" ,
70+ })
71+ logger .SetAsync ()
72+
73+ b .ResetTimer ()
74+ b .RunParallel (func (pb * testing.PB ) {
75+ for pb .Next () {
76+ logger .Info ("benchmark logger message" )
77+ }
78+ })
79+ logger .Flush ()
80+ }
81+
82+ // go test -run=benchmark -cpu=1,2,4 -benchmem -benchtime=3s -bench="FileJson"
83+ func BenchmarkLoggerFileJson (b * testing.B ) {
84+ logger := NewLogger ()
85+ logger .Detach ("console" )
86+ logger .Attach ("file" , LOGGER_LEVEL_DEBUG , & FileConfig {
87+ Filename :"./test.log" ,
88+ DateSlice : "d" ,
89+ JsonFormat : true ,
90+ })
91+ b .ResetTimer ()
92+ b .RunParallel (func (pb * testing.PB ) {
93+ for pb .Next () {
94+ logger .Info ("benchmark logger message" )
95+ }
96+ })
97+ }
0 commit comments