Skip to content

Commit

Permalink
split workloads
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Feb 4, 2021
1 parent 33e4cf1 commit 1332b00
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
33 changes: 33 additions & 0 deletions bench/workload_chan.go
Original file line number Diff line number Diff line change
@@ -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
}
27 changes: 0 additions & 27 deletions bench/workloads.go → bench/workload_mutex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1332b00

Please sign in to comment.