Created
October 5, 2024 15:18
-
-
Save skshahriarahmedraka/f2a69a10ff6c8286ab243366fa789389 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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