diff options
author | Christian Pointner <equinox@anytun.org> | 2017-10-13 23:03:59 +0200 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2017-10-13 23:03:59 +0200 |
commit | 081b6ab792df9d64c5fa55b2604a2e33032f9606 (patch) | |
tree | 057b461de7d2ac4a7068fed04b53309d0e2421d4 /satp | |
parent | added benchmarks for seq window (diff) |
added paralell benchmkarks for sequence window
Diffstat (limited to 'satp')
-rw-r--r-- | satp/sequence-window_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/satp/sequence-window_test.go b/satp/sequence-window_test.go index 3678d85..d52dead 100644 --- a/satp/sequence-window_test.go +++ b/satp/sequence-window_test.go @@ -31,6 +31,8 @@ package satp import ( + "runtime" + "sync" "testing" ) @@ -239,6 +241,31 @@ func BenchmarkSeqWindowCheck(b *testing.B) { } } +func BenchmarkSeqWindowCheckParallel(b *testing.B) { + w, err := NewSequenceWindow(100, 0) + if err != nil { + b.Fatal("unexpected error:", err) + } + + wg := sync.WaitGroup{} + numThreads := runtime.NumCPU() + b.Logf("running test with %d threads", numThreads) + wg.Add(numThreads) + + b.ResetTimer() + + for i := 0; i < numThreads; i++ { + go func() { + for seq := uint32(0); seq < uint32(b.N); seq += uint32(numThreads) { + w.Check(seq) + } + wg.Done() + }() + } + + wg.Wait() +} + func BenchmarkSeqWindowCheckAndSet(b *testing.B) { w, err := NewSequenceWindow(100, 0) if err != nil { @@ -251,3 +278,28 @@ func BenchmarkSeqWindowCheckAndSet(b *testing.B) { w.CheckAndSet(seq) } } + +func BenchmarkSeqWindowCheckAndSetParallel(b *testing.B) { + w, err := NewSequenceWindow(100, 0) + if err != nil { + b.Fatal("unexpected error:", err) + } + + wg := sync.WaitGroup{} + numThreads := runtime.NumCPU() + b.Logf("running test with %d threads", numThreads) + wg.Add(numThreads) + + b.ResetTimer() + + for i := 0; i < numThreads; i++ { + go func() { + for seq := uint32(0); seq < uint32(b.N); seq += uint32(numThreads) { + w.CheckAndSet(seq) + } + wg.Done() + }() + } + + wg.Wait() +} |