go test -coverprofile=c.out
go tool cover -html=c.out
go test -bench . -cpuprofile=cpu.profile
go tool pprof cpu.profile
func ExampleQueue_Pop() {
q := Queue{1}
q.Push(2)
q.Push(3)
fmt.Println(q.Pop())
fmt.Println(q.Pop())
fmt.Println(q.IsEmpty())
fmt.Println(q.Pop())
fmt.Println(q.IsEmpty())
//Output:
//1
//2
//false
//31
//true
}
- I/O,select
- channel
- 等待锁
- 函数调用(有时)
- runtime.Gosched() 只是参考,不保证切换,其它地方也不保证不切换
go run -race goroutine.go
不要使用共享内存来同步数据,使用chan来同步
- WaitGroup
- Mutex
- Cond
- pprof
http://localhost:8888/debug/pprof
import(
_ "net/http/pprof"
)
or
go tool pprof http://localhost:8888/debug/pprof/profile
go tool pprof http://localhost:8888/debug/pprof/heap
godoc -http :8888