Skip to content

Instantly share code, notes, and snippets.

@defp
Created May 21, 2020 11:10
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 defp/56f333fea2b5bdaae65f0bf96574e8f0 to your computer and use it in GitHub Desktop.
Save defp/56f333fea2b5bdaae65f0bf96574e8f0 to your computer and use it in GitHub Desktop.
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