forked from utahta/go-cronowriter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriter_benchmark_test.go
48 lines (41 loc) · 1.07 KB
/
writer_benchmark_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
package cronowriter
import (
"io/ioutil"
"path/filepath"
"testing"
)
func BenchmarkCronoWriter_Write(b *testing.B) {
stubNow("2017-02-06 20:30:00 +0900")
tmpDir, err := ioutil.TempDir("", "cronowriter")
if err != nil {
b.Fatal(err)
}
c := MustNew(filepath.Join(tmpDir, "benchmark.log.%Y%m%d"))
for i := 0; i < b.N; i++ {
c.Write([]byte("abcdefg"))
}
}
func BenchmarkCronoWriter_WriteWithMutex(b *testing.B) {
stubNow("2017-02-06 20:30:00 +0900")
tmpDir, err := ioutil.TempDir("", "cronowriter")
if err != nil {
b.Fatal(err)
}
c := MustNew(filepath.Join(tmpDir, "benchmark.log.%Y%m%d"), WithMutex())
for i := 0; i < b.N; i++ {
c.Write([]byte("abcdefg"))
}
}
func BenchmarkCronoWriter_WriteWithDebug(b *testing.B) {
stubNow("2017-02-06 20:30:00 +0900")
tmpDir, err := ioutil.TempDir("", "cronowriter")
if err != nil {
b.Fatal(err)
}
c := MustNew(filepath.Join(tmpDir, "benchmark.log.%Y%m%d"), WithDebug())
c.log.(*debugLogger).stdout = ioutil.Discard
c.log.(*debugLogger).stderr = ioutil.Discard
for i := 0; i < b.N; i++ {
c.Write([]byte("abcdefg"))
}
}