aboutsummaryrefslogtreecommitdiff
path: root/src/time
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2024-03-21 11:33:24 -0700
committerGopher Robot <gobot@golang.org>2024-03-22 16:33:57 +0000
commit1c864333cac25273ebfcefa53d50a82c270ebdab (patch)
tree314cb0561312e9506d8c76b7ca2f3d27167148fc /src/time
parentc2b1463153e0095cf66ca362409d70ff0b6aad26 (diff)
downloadgo-1c864333cac25273ebfcefa53d50a82c270ebdab.tar.gz
go-1c864333cac25273ebfcefa53d50a82c270ebdab.zip
runtime: add fast path for (*timers).adjust
Affected benchmark results, including new benchmark (some of these may just be noise, of course): AdjustTimers10000-12 797.7µ ± 2% 709.6µ ± 2% -11.04% (p=0.000 n=10) TickerResetNaive-12 62.69n ± 1% 63.56n ± 1% +1.40% (p=0.018 n=10) NowUnixMicro-12 29.95n ± 1% 30.25n ± 4% +1.00% (p=0.024 n=10) ParseDuration-12 81.88n ± 0% 81.45n ± 0% -0.51% (p=0.006 n=10) UnmarshalText-12 186.9n ± 1% 185.2n ± 1% -0.88% (p=0.006 n=10) geomean 151.8n 151.2n -0.40% Change-Id: I3ef8356249c5d703b314498e34ee8095093671c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/573455 Reviewed-by: Austin Clements <austin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/time')
-rw-r--r--src/time/sleep_test.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/time/sleep_test.go b/src/time/sleep_test.go
index 634a5c7a13..29f56ef752 100644
--- a/src/time/sleep_test.go
+++ b/src/time/sleep_test.go
@@ -971,3 +971,21 @@ func doWork(dur Duration) {
for Since(start) < dur {
}
}
+
+func BenchmarkAdjustTimers10000(b *testing.B) {
+ benchmark(b, func(pb *testing.PB) {
+ for pb.Next() {
+ const n = 10000
+ timers := make([]*Timer, 0, n)
+ for range n {
+ t := AfterFunc(Hour, func() {})
+ timers = append(timers, t)
+ }
+ timers[n-1].Reset(Nanosecond)
+ Sleep(Microsecond)
+ for _, t := range timers {
+ t.Stop()
+ }
+ }
+ })
+}