1
0
mirror of https://github.com/DataDog/go-profiler-notes.git synced 2025-07-12 23:50:13 +02:00
Files
go-profiler-notes/bench/workload_chan.go

34 lines
578 B
Go
Raw Permalink Normal View History

2021-02-03 11:16:38 +01:00
package main
import (
"fmt"
"sync"
)
2021-02-03 15:06:19 +01:00
func chanWorkload(goroutines, ops, depth, bufsize int) error {
2021-02-03 11:16:38 +01:00
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++ {
2021-02-03 15:06:19 +01:00
ch := make(chan struct{}, bufsize)
2021-02-03 11:16:38 +01:00
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
}