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

split workloads

This commit is contained in:
Felix Geisendörfer
2021-02-04 14:30:29 +01:00
parent 33e4cf1d9c
commit 1332b004e0
2 changed files with 33 additions and 27 deletions

33
bench/workload_chan.go Normal file
View File

@ -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
}

View File

@ -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)