Commit b0ac2546 authored by Carl Mastrangelo's avatar Carl Mastrangelo Committed by Brad Fitzpatrick

context: add benchmarks for context cancellation

Change-Id: I539c9226eb7e493b52c50e1e431954567d43bcfb
Reviewed-on: https://go-review.googlesource.com/100847Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 210a9e0c
......@@ -13,6 +13,30 @@ import (
"time"
)
func BenchmarkCommonParentCancel(b *testing.B) {
root := WithValue(Background(), "key", "value")
shared, sharedcancel := WithCancel(root)
defer sharedcancel()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
x := 0
for pb.Next() {
ctx, cancel := WithCancel(shared)
if ctx.Value("key").(string) != "value" {
b.Fatal("should not be reached")
}
for i := 0; i < 100; i++ {
x /= x + 1
}
cancel()
for i := 0; i < 100; i++ {
x /= x + 1
}
}
})
}
func BenchmarkWithTimeout(b *testing.B) {
for concurrency := 40; concurrency <= 4e5; concurrency *= 100 {
name := fmt.Sprintf("concurrency=%d", concurrency)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment