/
main.go
60 lines (53 loc) · 1.32 KB
/
main.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
package main
import (
"bytes"
"fmt"
"time"
"github.com/antlinker/alog"
)
const (
// 写入日志条数
_LogNum = 100000
// 日志信息长度
_DataLen = 512
)
var (
_GCHComplete chan time.Time
)
func logData() string {
buf := new(bytes.Buffer)
for i := 0; i < _DataLen; i++ {
buf.WriteByte('a')
}
return buf.String()
}
func main() {
_GCHComplete = make(chan time.Time, 1)
startTime := time.Now()
alog.RegisterAlog("config.yaml")
alog.GALog.SetLogTag("REDIS")
ticker := time.NewTicker(time.Second)
go output(startTime, ticker)
go func() {
logInfo := logData()
for i := 0; i < _LogNum; i++ {
alog.Info(logInfo)
}
}()
endTime := <-_GCHComplete
useSecond := float64(endTime.Sub(startTime))/float64(time.Second) - 1
fmt.Printf("\n===> 文件日志写入\n===> 总条数:%d,总耗时:%.2fs,每条日志长度:%d,每秒写入日志条数:%d\n",
_LogNum, useSecond, _DataLen, int64(_LogNum)/int64(useSecond))
}
func output(startTime time.Time, ticker *time.Ticker) {
for t := range ticker.C {
totalNum := alog.GALog.GetWriteNum()
currentSecond := float64(t.Sub(startTime)) / float64(time.Second)
info := fmt.Sprintf("\r ===> 写入日志条数:%d,用时:%.2fs", totalNum, currentSecond)
fmt.Print(info)
if totalNum == int64(_LogNum) {
ticker.Stop()
_GCHComplete <- time.Now()
}
}
}