diff --git a/bench/workload_chan.go b/bench/workload_chan.go new file mode 100644 index 0000000..c75b85c --- /dev/null +++ b/bench/workload_chan.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "sync" +) + +func chanWorkload(goroutines, ops, depth, bufsize int) error { + if goroutines%2 != 0 { + return fmt.Errorf("bad goroutines: %d: must be a multiple of 2", goroutines) + } + + wg := &sync.WaitGroup{} + for j := 0; j < goroutines/2; j++ { + ch := make(chan struct{}, bufsize) + wg.Add(1) + go atStackDepth(depth, func() { + defer wg.Done() + for i := 0; i < ops; i++ { + ch <- struct{}{} + } + }) + wg.Add(1) + go atStackDepth(depth, func() { + defer wg.Done() + for i := 0; i < ops; i++ { + <-ch + } + }) + } + wg.Wait() + return nil +} diff --git a/bench/workloads.go b/bench/workload_mutex.go similarity index 51% rename from bench/workloads.go rename to bench/workload_mutex.go index 9315dfc..90b9883 100644 --- a/bench/workloads.go +++ b/bench/workload_mutex.go @@ -5,33 +5,6 @@ import ( "sync" ) -func chanWorkload(goroutines, ops, depth, bufsize int) error { - if goroutines%2 != 0 { - return fmt.Errorf("bad goroutines: %d: must be a multiple of 2", goroutines) - } - - wg := &sync.WaitGroup{} - for j := 0; j < goroutines/2; j++ { - ch := make(chan struct{}, bufsize) - wg.Add(1) - go atStackDepth(depth, func() { - defer wg.Done() - for i := 0; i < ops; i++ { - ch <- struct{}{} - } - }) - wg.Add(1) - go atStackDepth(depth, func() { - defer wg.Done() - for i := 0; i < ops; i++ { - <-ch - } - }) - } - wg.Wait() - return nil -} - func mutexWorkload(goroutines, ops, depth int) error { if goroutines%2 != 0 { return fmt.Errorf("bad goroutines: %d: must be a multiple of 2", goroutines)