From 83232a78369959cd1e5cb2f1ed02db2bfb7552dd Mon Sep 17 00:00:00 2001 From: corvinFn Date: Mon, 27 Nov 2023 15:13:51 +0800 Subject: [PATCH] benchmark parallel --- Makefile | 2 +- benchmark_timewheel_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b15a2be..02713da 100644 --- a/Makefile +++ b/Makefile @@ -29,4 +29,4 @@ lint_check: .PHONY: test test: - $(GO) test -race -v -cover -coverprofile=cover.out ./... + $(GO) test -race -v -p 4 -race -cover -coverprofile=cover.out ./... diff --git a/benchmark_timewheel_test.go b/benchmark_timewheel_test.go index a20c255..2a8f9ad 100644 --- a/benchmark_timewheel_test.go +++ b/benchmark_timewheel_test.go @@ -25,3 +25,23 @@ func BenchmarkTimeWheelTest(b *testing.B) { time.Sleep(100 * time.Millisecond) require.EqualValues(b, b.N, atomic.LoadInt32(&num)) } + +func BenchmarkTimeWheelParallelTest(b *testing.B) { + const delay = 10 * time.Millisecond + num := int32(0) + tw, _ := NewTimeWheel(10*time.Millisecond, 3600) + tw.activate() + defer tw.stop() + f := func() { + atomic.AddInt32(&num, 1) + } + b.ReportAllocs() + b.ResetTimer() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + tw.addTimer(delay, f, false) + time.Sleep(100 * time.Millisecond) + } + }) + require.EqualValues(b, b.N, atomic.LoadInt32(&num)) +}