refactor: move averageReadTime out of loop

This commit is contained in:
Derrick Hammer 2024-02-28 12:59:11 -05:00
parent 68d82390ed
commit 7abba4ac8e
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 8 additions and 5 deletions

View File

@ -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))