// Since returns the time elapsed since t.
// It is shorthand for time.Now().Sub(t).
func Since(t Time) Duration {
- return Now().Sub(t)
+ var now Time
+ if t.wall&hasMonotonic != 0 {
+ // Common case optimization: if t has monotomic time, then Sub will use only it.
+ now = Time{hasMonotonic, runtimeNano() - startNano, nil}
+ } else {
+ now = Now()
+ }
+ return now.Sub(t)
}
// Until returns the duration until t.
// It is shorthand for t.Sub(time.Now()).
func Until(t Time) Duration {
- return t.Sub(Now())
+ var now Time
+ if t.wall&hasMonotonic != 0 {
+ // Common case optimization: if t has monotomic time, then Sub will use only it.
+ now = Time{hasMonotonic, runtimeNano() - startNano, nil}
+ } else {
+ now = Now()
+ }
+ return t.Sub(now)
}
// AddDate returns the time corresponding to adding the