diff options
| author | Damien Neil <dneil@google.com> | 2025-02-28 15:22:58 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-03-03 12:32:57 -0800 |
| commit | 0a0e6af39b0ff38f7d5a8a9f3f6d38ebc081663f (patch) | |
| tree | 5eaffcb870f70fee1cebf89c1c0ab9f900051ce2 /src/context/benchmark_test.go | |
| parent | 14647b0ac881f084f0063ddb32341fba71e1d2e4 (diff) | |
| download | go-0a0e6af39b0ff38f7d5a8a9f3f6d38ebc081663f.tar.xz | |
context: use atomic operation in ctx.Err
oos: darwin
goarch: arm64
pkg: context
cpu: Apple M1 Pro
│ /tmp/bench.0.mac │ /tmp/bench.1.mac │
│ sec/op │ sec/op vs base │
ErrOK-10 13.750n ± 1% 2.080n ± 0% -84.87% (p=0.000 n=10)
ErrCanceled-10 13.530n ± 1% 3.248n ± 1% -76.00% (p=0.000 n=10)
geomean 13.64n 2.599n -80.94%
goos: linux
goarch: amd64
pkg: context
cpu: Intel(R) Xeon(R) CPU @ 2.30GHz
│ /tmp/bench.0.linux │ /tmp/bench.1.linux │
│ sec/op │ sec/op vs base │
ErrOK-16 21.435n ± 0% 4.243n ± 0% -80.21% (p=0.000 n=10)
ErrCanceled-16 21.445n ± 0% 5.070n ± 0% -76.36% (p=0.000 n=10)
geomean 21.44n 4.638n -78.37%
Fixes #72040
Change-Id: I3b337ab1934689d2da4134492ee7c5aac8f92845
Reviewed-on: https://go-review.googlesource.com/c/go/+/653795
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/context/benchmark_test.go')
| -rw-r--r-- | src/context/benchmark_test.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/context/benchmark_test.go b/src/context/benchmark_test.go index 144f473a44..d10950d258 100644 --- a/src/context/benchmark_test.go +++ b/src/context/benchmark_test.go @@ -188,3 +188,23 @@ func BenchmarkDeepValueSameGoRoutine(b *testing.B) { }) } } + +func BenchmarkErrOK(b *testing.B) { + ctx, cancel := WithCancel(Background()) + defer cancel() + for b.Loop() { + if err := ctx.Err(); err != nil { + b.Fatalf("ctx.Err() = %v", err) + } + } +} + +func BenchmarkErrCanceled(b *testing.B) { + ctx, cancel := WithCancel(Background()) + cancel() + for b.Loop() { + if err := ctx.Err(); err == nil { + b.Fatalf("ctx.Err() = %v", err) + } + } +} |
