forked from templexxx/logro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperf_test.go
80 lines (66 loc) · 1.35 KB
/
perf_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
/*
* Copyright (c) 2019. Temple3x ([email protected])
*
* Use of this source code is governed by the MIT License
* that can be found in the LICENSE file.
*/
package logro
import (
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"testing"
)
// This bench is only for non-blocking model,
// that means all write are same for Write.
//
// If there is write stall which will impact user-facing write,
// it shouldn't use this bench.
func BenchmarkRotation_Write(b *testing.B) {
dir, err := ioutil.TempDir(os.TempDir(), "")
if err != nil {
b.Fatal(err)
}
defer os.RemoveAll(dir)
fn := "logro-perf-write-test.log"
fp := filepath.Join(dir, fn)
cfg := new(Config)
cfg.OutputPath = fp
r, err := New(cfg)
if err != nil {
b.Fatal(err)
}
defer r.Close()
p := make([]byte, 256)
rand.Read(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.Write(p)
}
}
// Same as BenchmarkRotation_Write.
func BenchmarkRotation_WriteParallel(b *testing.B) {
dir, err := ioutil.TempDir(os.TempDir(), "")
if err != nil {
b.Fatal(err)
}
defer os.RemoveAll(dir)
fn := "logro-perf-write-test.log"
fp := filepath.Join(dir, fn)
cfg := new(Config)
cfg.OutputPath = fp
r, err := New(cfg)
if err != nil {
b.Fatal(err)
}
defer r.Close()
p := make([]byte, 256)
rand.Read(p)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
r.Write(p)
}
})
}