mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
all: use time.Since instead of time.Now().Sub
Change-Id: Ifaa73b64e5b6a1d37c753e2440b642478d7dfbce Reviewed-on: https://go-review.googlesource.com/c/go/+/436957 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: hopehook <hopehook@golangcn.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
51297dd6df
commit
4585bf96b4
8 changed files with 9 additions and 9 deletions
2
src/go/doc/testdata/benchmark.go
vendored
2
src/go/doc/testdata/benchmark.go
vendored
|
|
@ -48,7 +48,7 @@ func (b *B) StartTimer() {
|
||||||
// want to measure.
|
// want to measure.
|
||||||
func (b *B) StopTimer() {
|
func (b *B) StopTimer() {
|
||||||
if b.timerOn {
|
if b.timerOn {
|
||||||
b.duration += time.Now().Sub(b.start)
|
b.duration += time.Since(b.start)
|
||||||
b.timerOn = false
|
b.timerOn = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
src/go/doc/testdata/example.go
vendored
2
src/go/doc/testdata/example.go
vendored
|
|
@ -59,7 +59,7 @@ func RunExamples(examples []InternalExample) (ok bool) {
|
||||||
// run example
|
// run example
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
eg.F()
|
eg.F()
|
||||||
dt := time.Now().Sub(t0)
|
dt := time.Since(t0)
|
||||||
|
|
||||||
// close pipe, restore stdout/stderr, get output
|
// close pipe, restore stdout/stderr, get output
|
||||||
w.Close()
|
w.Close()
|
||||||
|
|
|
||||||
2
src/go/doc/testdata/testing.go
vendored
2
src/go/doc/testdata/testing.go
vendored
|
|
@ -219,7 +219,7 @@ func tRunner(t *T, test *InternalTest) {
|
||||||
// a call to runtime.Goexit, record the duration and send
|
// a call to runtime.Goexit, record the duration and send
|
||||||
// a signal saying that the test is done.
|
// a signal saying that the test is done.
|
||||||
defer func() {
|
defer func() {
|
||||||
t.duration = time.Now().Sub(t.start)
|
t.duration = time.Since(t.start)
|
||||||
t.signal <- t
|
t.signal <- t
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ func dialClosedPort(t *testing.T) (dialLatency time.Duration) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
elapsed := time.Now().Sub(startTime)
|
elapsed := time.Since(startTime)
|
||||||
t.Logf("dialClosedPort: measured delay %v", elapsed)
|
t.Logf("dialClosedPort: measured delay %v", elapsed)
|
||||||
return elapsed
|
return elapsed
|
||||||
}
|
}
|
||||||
|
|
@ -366,7 +366,7 @@ func TestDialerFallbackDelay(t *testing.T) {
|
||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
c, err := d.Dial("tcp", JoinHostPort("slow6loopback4", dss.port))
|
c, err := d.Dial("tcp", JoinHostPort("slow6loopback4", dss.port))
|
||||||
elapsed := time.Now().Sub(startTime)
|
elapsed := time.Since(startTime)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.Close()
|
c.Close()
|
||||||
} else if tt.dualstack {
|
} else if tt.dualstack {
|
||||||
|
|
|
||||||
|
|
@ -689,7 +689,7 @@ func BenchmarkReadMemStatsLatency(b *testing.B) {
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
runtime.ReadMemStats(&ms)
|
runtime.ReadMemStats(&ms)
|
||||||
latencies = append(latencies, time.Now().Sub(start))
|
latencies = append(latencies, time.Since(start))
|
||||||
}
|
}
|
||||||
// Make sure to stop the timer before we wait! The load created above
|
// Make sure to stop the timer before we wait! The load created above
|
||||||
// is very heavy-weight and not easy to stop, so we could end up
|
// is very heavy-weight and not easy to stop, so we could end up
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,7 @@ func BenchmarkReadMetricsLatency(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
metrics.Read(samples)
|
metrics.Read(samples)
|
||||||
latencies = append(latencies, time.Now().Sub(start))
|
latencies = append(latencies, time.Since(start))
|
||||||
}
|
}
|
||||||
// Make sure to stop the timer before we wait! The load created above
|
// Make sure to stop the timer before we wait! The load created above
|
||||||
// is very heavy-weight and not easy to stop, so we could end up
|
// is very heavy-weight and not easy to stop, so we could end up
|
||||||
|
|
|
||||||
|
|
@ -377,7 +377,7 @@ func BenchmarkGoroutineProfile(b *testing.B) {
|
||||||
if !ok {
|
if !ok {
|
||||||
b.Fatal("goroutine profile failed")
|
b.Fatal("goroutine profile failed")
|
||||||
}
|
}
|
||||||
latencies = append(latencies, time.Now().Sub(start))
|
latencies = append(latencies, time.Since(start))
|
||||||
}
|
}
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
|
|
||||||
|
|
|
||||||
2
src/runtime/testdata/testprog/gc.go
vendored
2
src/runtime/testdata/testprog/gc.go
vendored
|
|
@ -396,7 +396,7 @@ func gcMemoryLimit(gcPercent int) {
|
||||||
// should do considerably better than this bound.
|
// should do considerably better than this bound.
|
||||||
bound := int64(myLimit + 16<<20)
|
bound := int64(myLimit + 16<<20)
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
for time.Now().Sub(start) < 200*time.Millisecond {
|
for time.Since(start) < 200*time.Millisecond {
|
||||||
metrics.Read(m[:])
|
metrics.Read(m[:])
|
||||||
retained := int64(m[0].Value.Uint64() - m[1].Value.Uint64())
|
retained := int64(m[0].Value.Uint64() - m[1].Value.Uint64())
|
||||||
if retained > bound {
|
if retained > bound {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue