Skip to content

Commit

Permalink
benchmark parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
corvinFn authored and corvinFn committed Nov 27, 2023
1 parent 1eed039 commit 83232a7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
20 changes: 20 additions & 0 deletions benchmark_timewheel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 83232a7

Please sign in to comment.