I'm learning how Go profilig works. So I do the following example
func Func() {
var b [][]byte
for i := 0; i < 8; i++ {
b = append(b, make([]byte, 8))
}
}
func BenchmarkFunc(b *testing.B) {
for i:=0; i<b.N; i++ {
Func()
}
}
then I run
go test -run none -bench Func -benchmem -memprofile mem.out
and
go tool pprof -alloc_space mem.out
(pprof) list Func
What I get is
Total: 1.61GB
ROUTINE ======================== test-mem/somepkg.BenchmarkFunc in .../work/go/src/test-mem/somepkg/somepkg_test.go
0 1.61GB (flat, cum) 100% of Total
. . 14://
. . 15:
. . 16:func BenchmarkFunc(b *testing.B) {
. . 17:
. . 18: for i:=0; i<b.N; i++ {
. 1.61GB 19: Func()
. . 20: }
. . 21:}
ROUTINE ======================== test-mem/somepkg.Func in .../go/src/test-mem/somepkg/somepkg.go
1.61GB 1.61GB (flat, cum) 100% of Total
. . 42:func Func() {
. . 43:
. . 44: var b [][]byte
. . 45:
. . 46: for i := 0; i < 8; i++ {
1.61GB 1.61GB 47: b = append(b, make([]byte, 8))
. . 48: }
. . 49:
. . 50:}
Why I get 1.61GB
allocation? Isn't it too much? How can I check what is one function run memory allocation?