Skip to content

Instantly share code, notes, and snippets.

@amyangfei
Created May 3, 2021 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amyangfei/7318dc0d3c6a59c9a3c1a185c153d024 to your computer and use it in GitHub Desktop.
Save amyangfei/7318dc0d3c6a59c9a3c1a185c153d024 to your computer and use it in GitHub Desktop.
package main
import (
"testing"
"strconv"
"sync"
)
func BenchmarkCreateGoroutine(b *testing.B) {
nums := []int {
1, 4, 16, 64, 256, 1024, 4096, 16384, 65536,
}
for _, num := range nums {
name := strconv.Itoa(num)
b.Run(name, func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N/num; i++ {
var wg sync.WaitGroup
wg.Add(num)
for j := 0; j < num; j++ {
go func() {
wg.Done()
}()
}
wg.Wait()
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment