Created
May 21, 2020 11:10
-
-
Save defp/56f333fea2b5bdaae65f0bf96574e8f0 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 ( | |
"fmt" | |
"runtime" | |
"sync" | |
) | |
func main() { | |
memConsumed := func() uint64 { | |
runtime.GC() | |
var s runtime.MemStats | |
runtime.ReadMemStats(&s) | |
return s.Sys | |
} | |
var c <-chan interface{} | |
var wg sync.WaitGroup | |
noop := func() { wg.Done(); <-c } | |
const numGoroutines = 1e4 | |
wg.Add(numGoroutines) | |
before := memConsumed() | |
for i := numGoroutines; i > 0; i-- { | |
go noop() | |
} | |
wg.Wait() | |
after := memConsumed() | |
fmt.Printf("%.3fkb", float64(after-before)/numGoroutines/1000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment