Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"runtime"
"time"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
var m runtime.MemStats
c := make(chan int, 10)
go func() {
for {
<-c
}
}()
for i := 0; i < 180; i++ {
c <- 1
time.Sleep(time.Second)
if i%10 == 0 {
runtime.ReadMemStats(&m)
println(i, m.HeapSys, m.HeapAlloc, m.HeapIdle)
}
}
}
package main
import (
"runtime"
"time"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
var m runtime.MemStats
c := make(chan int, 10)
go func() {
for {
select {
case <-c:
case <-time.After(time.Second):
}
}
}()
for i := 0; i < 180; i++ {
select {
case c <- 1:
case <-time.After(time.Second):
}
time.Sleep(time.Second)
if i%10 == 0 {
runtime.ReadMemStats(&m)
println(i, m.HeapSys, m.HeapAlloc, m.HeapIdle)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment