go test -cover
直接輸出覆蓋率go test -run TestAll
指定要運行的單元測試函數go test -cover -coverprofile=c.out
go tool cover -html=c.out -o coverage.html
輸出具體的代碼覆蓋狀況執行全部函數 go test -bench=".*"
html
執行指定函數 go test -bench="BenchmarkWithPool"
git
生成內存和cpu分析文件 go test -bench="BenchmarkWithPool" -cpuprofile cpu.out -memprofile mem.out
github
分析cpu文件 go tool pprof cpu.out
golang
分析內存文件 go tool pprof mem.out
函數
輸出png圖 圖中紅色方塊面積越大 證實申請的內存越大或者消耗cpu越多性能
源碼連接單元測試