refactor: move averageReadTime out of loop
This commit is contained in:
parent
68d82390ed
commit
7abba4ac8e
13
bao/bao.go
13
bao/bao.go
|
@ -64,11 +64,6 @@ func (v *Verifier) Read(p []byte) (int, error) {
|
|||
readEnd := time.Now()
|
||||
|
||||
v.readTime = append(v.readTime, readEnd.Sub(readStart))
|
||||
averageReadTime := lo.Reduce(v.readTime, func(acc time.Duration, cur time.Duration, _ int) time.Duration {
|
||||
return acc + cur
|
||||
}, time.Duration(0)) / time.Duration(len(v.readTime))
|
||||
|
||||
v.logger.Debug("Read time", zap.Duration("average", averageReadTime))
|
||||
|
||||
timeStart := time.Now()
|
||||
|
||||
|
@ -88,6 +83,14 @@ func (v *Verifier) Read(p []byte) (int, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if len(v.readTime) > 0 {
|
||||
averageReadTime := lo.Reduce(v.readTime, func(acc time.Duration, cur time.Duration, _ int) time.Duration {
|
||||
return acc + cur
|
||||
}, time.Duration(0)) / time.Duration(len(v.readTime))
|
||||
|
||||
v.logger.Debug("Read time", zap.Duration("average", averageReadTime))
|
||||
}
|
||||
|
||||
averageVerifyTime := v.verifyTime / time.Duration(v.read/VERIFY_CHUNK_SIZE)
|
||||
v.logger.Debug("Verification time", zap.Duration("average", averageVerifyTime))
|
||||
|
||||
|
|
Loading…
Reference in New Issue