Created
May 3, 2021 12:29
-
-
Save amyangfei/7318dc0d3c6a59c9a3c1a185c153d024 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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