Go 有没有人有一个简单的可执行程序?

Go 有没有人有一个简单的可执行程序?,go,Go,我已经看了这篇文章,我简直不懂它。是否有人有一个简单的代码示例,代码片段的性能是通过配置文件“object”记录在文本文件中的?以下是我用于简单CPU和内存配置文件的命令,让您开始 假设您制作了如下基准函数: 将某物归档\u test.go: func BenchmarkProfileMe(b *testing.B) { // execute the significant portion of the code you want to profile b.N times } 在shell脚

我已经看了这篇文章,我简直不懂它。是否有人有一个简单的代码示例,代码片段的性能是通过配置文件“object”记录在文本文件中的?

以下是我用于简单CPU和内存配置文件的命令,让您开始

假设您制作了如下基准函数:

将某物归档\u test.go:

func BenchmarkProfileMe(b *testing.B) {
 // execute the significant portion of the code you want to profile b.N times
}
在shell脚本中:

# -test XXX is a trick so you don't trigger other tests by asking a non existent specific test called literally XXX
# you can adapt the benchtime depending on the type of code you want to profile.

go test -v -bench ProfileMe -test.run XXX -cpuprofile cpu.pprof -memprofile mem.pprof -benchtime 10s

go tool pprof --text ./something.test cpu.pprof           ## To get a CPU profile per function

go tool pprof --text ./something.test cpu.pprof --lines   ## To get a CPU profile per line

go tool pprof --text ./something.test mem.pprof           ## To get the memory profile

它将在控制台上为您显示每种情况下的热点测试点。

您需要哪种分析信息?golang中的pprof工具可以提供很多不同的信息。我发现一个有用的功能是列表功能,它只输出源代码和每行代码上的采样数。