Hello, I'm a beginner in Go and I'm having trouble figuring out how much memory the code in Go needed to execute some code. I did the memory () function that even returns something, but I do not know what it would be like to bring the return I want, it would be like: the code needed 15MB to run, for example would have how to do this? Thank you in advance!
package main
import (
"fmt"
"log"
"runtime"
"time"
)
func ack(m, n uint) uint {
if m == 0 {
return n + 1
} else if n == 0 {
return ack(m - 1, 1)
} else {
return ack(m - 1, ack(m, n - 1))
}
}
func memory(){
for {
var m runtime.MemStats
runtime.ReadMemStats(&m)
log.Printf("\nAlloc = %v\nTotalAlloc = %v\nSys = %v\nNumGC = %v\n\n", m.Alloc / 1024, m.TotalAlloc / 1024, m.Sys / 1024, m.NumGC)
time.Sleep(5 * time.Second)
}
}
func main() {
var inicio = time.Now().UnixNano()
fmt.Println(ack(1,2))
var fim = time.Now().UnixNano()
fmt.Println(fim - inicio)
memory()
}