Skip to content

Instantly share code, notes, and snippets.

@skshahriarahmedraka
Created October 5, 2024 15:18
Show Gist options
  • Save skshahriarahmedraka/f2a69a10ff6c8286ab243366fa789389 to your computer and use it in GitHub Desktop.
Save skshahriarahmedraka/f2a69a10ff6c8286ab243366fa789389 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"runtime"
)
func printMemStats() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc))
fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))
fmt.Printf("\tNumber of Garbase Collector = %v\n", m.NumGC)
}
func bToMb(b uint64) uint64 {
return b / 1024 / 1024
}
func main() {
fmt.Println("Mem Stats Before:")
printMemStats()
var s []int
for i := 0; i < 1000000; i++ {
s = append(s, i)
}
fmt.Println("Mem Stats After:")
printMemStats()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment