quasilyte/go-perfguard

Suggest Time.Sub instead of time.Now+time.Since

quasilyte opened this issue · 0 comments

time.Since() executed time.Now() under the hood.
If we need time.Time as well as time.Duration (since), we can do this optimization:

elapsed := time.Since(oldTime)
oldTime = time.Now()

// =>

newTime := time.Now()
elapsed := newTime.Sub(oldTime)
oldTime = newTime