-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
License: MIT Signed-off-by: Jakub Sztandera <[email protected]>
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package log | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
) | ||
|
||
// To run bencharks: | ||
// > go test -c . | ||
// > ./go-log.test -test.run NONE -test.bench . 2>/dev/null | ||
// Otherwise you test how fast your terminal can print. | ||
|
||
func BenchmarkSimpleInfo(b *testing.B) { | ||
l := Logger("bench") | ||
SetLogLevel("bench", "info") | ||
|
||
b.ResetTimer() | ||
b.ReportAllocs() | ||
for i := 0; i < b.N; i++ { | ||
l.Info("test") | ||
} | ||
} | ||
|
||
var logString = "String, IDK what to write, let's punch a keyboard. jkdlsjklfdjfklsjfklsdjaflkdjfkdjsfkldjsfkdjklfjdslfjakdfjioerjieofjofdnvonoijdfneslkffjsdfljadljfdjkfjkf" | ||
|
||
func BenchmarkFormatInfo(b *testing.B) { | ||
l := Logger("bench") | ||
SetLogLevel("bench", "info") | ||
|
||
b.ResetTimer() | ||
b.ReportAllocs() | ||
for i := 0; i < b.N; i++ { | ||
l.Infof("test %d %s", logString) | ||
} | ||
} | ||
|
||
func BenchmarkFormatInfoMulti(b *testing.B) { | ||
l := Logger("bench") | ||
SetLogLevel("bench", "info") | ||
var wg sync.WaitGroup | ||
|
||
goroutines := 16 | ||
|
||
run := func() { | ||
for i := 0; i < b.N/goroutines; i++ { | ||
l.Infof("test %d %s", i, logString) | ||
} | ||
wg.Done() | ||
} | ||
|
||
wg.Add(goroutines) | ||
|
||
b.ResetTimer() | ||
b.ReportAllocs() | ||
for i := 0; i < goroutines; i++ { | ||
go run() | ||
} | ||
wg.Wait() | ||
} |