From 61b10135715446dc7b8eeeb0104a3fa08a3bc008 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 14 Nov 2018 21:00:51 +0100 Subject: [PATCH] benchmark task --- common/task/task_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/common/task/task_test.go b/common/task/task_test.go index 886564106..02335ba99 100644 --- a/common/task/task_test.go +++ b/common/task/task_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "v2ray.com/core/common" . "v2ray.com/core/common/task" . "v2ray.com/ext/assert" ) @@ -41,3 +42,32 @@ func TestExecuteParallelContextCancel(t *testing.T) { assert(err.Error(), HasSubstring, "canceled") } + +func BenchmarkExecuteOne(b *testing.B) { + noop := func() error { + return nil + } + for i := 0; i < b.N; i++ { + common.Must(Run(Parallel(noop))()) + } +} + +func BenchmarkExecuteTwo(b *testing.B) { + noop := func() error { + return nil + } + for i := 0; i < b.N; i++ { + common.Must(Run(Parallel(noop, noop))()) + } +} + +func BenchmarkExecuteContext(b *testing.B) { + noop := func() error { + return nil + } + background := context.Background() + + for i := 0; i < b.N; i++ { + common.Must(Run(WithContext(background), Parallel(noop, noop))()) + } +}