]> Cypherpunks repositories - gostls13.git/commitdiff
all: use time.Since instead of time.Now().Sub
authorhopehook <hopehook.com@gmail.com>
Fri, 30 Sep 2022 02:29:30 +0000 (10:29 +0800)
committerGopher Robot <gobot@golang.org>
Sun, 2 Oct 2022 02:28:27 +0000 (02:28 +0000)
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>

src/go/doc/testdata/benchmark.go
src/go/doc/testdata/example.go
src/go/doc/testdata/testing.go
src/net/dial_test.go
src/runtime/gc_test.go
src/runtime/metrics_test.go
src/runtime/runtime_test.go
src/runtime/testdata/testprog/gc.go

index d27bf116aafa902a46cfbf55729760f158f028e6..dbf6b4ffad767183bc51d8d18ff8dbbd3c398c2b 100644 (file)
@@ -48,7 +48,7 @@ func (b *B) StartTimer() {
 // want to measure.
 func (b *B) StopTimer() {
        if b.timerOn {
-               b.duration += time.Now().Sub(b.start)
+               b.duration += time.Since(b.start)
                b.timerOn = false
        }
 }
index fdeda137e7614facde2b4a4ade14e67970610ade..0b7033980182a3a8872490e77ee6cd0546580755 100644 (file)
@@ -59,7 +59,7 @@ func RunExamples(examples []InternalExample) (ok bool) {
                // run example
                t0 := time.Now()
                eg.F()
-               dt := time.Now().Sub(t0)
+               dt := time.Since(t0)
 
                // close pipe, restore stdout/stderr, get output
                w.Close()
index 6365ffceedc6dda957eb4b6e73ca59efe2307f05..d3076c95b502736b2ae9d7bf3d3efec20258b121 100644 (file)
@@ -219,7 +219,7 @@ func tRunner(t *T, test *InternalTest) {
        // a call to runtime.Goexit, record the duration and send
        // a signal saying that the test is done.
        defer func() {
-               t.duration = time.Now().Sub(t.start)
+               t.duration = time.Since(t.start)
                t.signal <- t
        }()
 
index 1256867da8db7777f0c9b6405cad546483f3288e..23e4a7a10ce1814a3702bf5b8e9bd59c2b8f240c 100644 (file)
@@ -171,7 +171,7 @@ func dialClosedPort(t *testing.T) (dialLatency time.Duration) {
        if err == nil {
                c.Close()
        }
-       elapsed := time.Now().Sub(startTime)
+       elapsed := time.Since(startTime)
        t.Logf("dialClosedPort: measured delay %v", elapsed)
        return elapsed
 }
@@ -366,7 +366,7 @@ func TestDialerFallbackDelay(t *testing.T) {
 
                startTime := time.Now()
                c, err := d.Dial("tcp", JoinHostPort("slow6loopback4", dss.port))
-               elapsed := time.Now().Sub(startTime)
+               elapsed := time.Since(startTime)
                if err == nil {
                        c.Close()
                } else if tt.dualstack {
index 122818fbfeba81245b4eeba1c5928cffd2b00a4b..0b2c972d3f3a6f6aecb9c51f48c79544025ebe44 100644 (file)
@@ -689,7 +689,7 @@ func BenchmarkReadMemStatsLatency(b *testing.B) {
                time.Sleep(100 * time.Millisecond)
                start := time.Now()
                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
        // is very heavy-weight and not easy to stop, so we could end up
index b4d921b82e47cc0e745aaea4645679180e3343e3..d981c8ee00b65abcbd38d86a5e0b8d36aa1359e2 100644 (file)
@@ -375,7 +375,7 @@ func BenchmarkReadMetricsLatency(b *testing.B) {
        for i := 0; i < b.N; i++ {
                start := time.Now()
                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
        // is very heavy-weight and not easy to stop, so we could end up
index 018a8dbaa68f54bb576c34547820ba39ebfd9a41..2faf06e2b9fca4297595a1677c07edf3046dfbdb 100644 (file)
@@ -377,7 +377,7 @@ func BenchmarkGoroutineProfile(b *testing.B) {
                                if !ok {
                                        b.Fatal("goroutine profile failed")
                                }
-                               latencies = append(latencies, time.Now().Sub(start))
+                               latencies = append(latencies, time.Since(start))
                        }
                        b.StopTimer()
 
index 0f44575381ed57f5efe1abba9faad314ca9f9ea4..5dc85fbb6247c54f48e06f959b4c47484f12d853 100644 (file)
@@ -396,7 +396,7 @@ func gcMemoryLimit(gcPercent int) {
                // should do considerably better than this bound.
                bound := int64(myLimit + 16<<20)
                start := time.Now()
-               for time.Now().Sub(start) < 200*time.Millisecond {
+               for time.Since(start) < 200*time.Millisecond {
                        metrics.Read(m[:])
                        retained := int64(m[0].Value.Uint64() - m[1].Value.Uint64())
                        if retained > bound {