Skip to content

Instantly share code, notes, and snippets.

@skoowoo
Created September 27, 2013 11:18
Show Gist options
  • Save skoowoo/6727151 to your computer and use it in GitHub Desktop.
Save skoowoo/6727151 to your computer and use it in GitHub Desktop.
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