1.分析程序的运行时间
(1)time指令(linux系统下)
time go run a.go
real:从程序开始到结束,实际上度过的时间
user:程序在用户态度过的时间
sys:程序在内核度过的时间
一般情况下,real>=user+sys
(2) /usr/bin/time 指令(linux系统下)
/usr/bin/time -v go run a.go
该指令下 可以看到 cpu占用率、 内存使用情况、 进程切换情况 、文件系统io、socket情况
2.golang下cpu性能分析
(1)在程序中引入 _ "net/http/pprof" ,并开启pprof监听
import _ "net/http/pprof"
<程序
http.ListenAndServe("0.0.0.0:10000", nil)
>
(2)通过浏览器查看
原文:https://www.cnblogs.com/peteremperor/p/13634486.html