概要
簡易的なパフォーマンス測定覚書です。
よく使うので備忘録的に保存。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| package main
import ( "fmt" "runtime" "time" )
func main() { cpus := runtime.NumCPU()
var startMemory runtime.MemStats runtime.ReadMemStats(&startMemory)
start := time.Now()
elapsed := time.Since(start)
var endMemory runtime.MemStats runtime.ReadMemStats(&endMemory)
fmt.Printf("実行時間: %f 秒 \n", elapsed.Seconds()) fmt.Printf("CPU: %d \n", cpus) fmt.Printf("Memory All: %f MB \n", float64(endMemory.Alloc-startMemory.Alloc)/float64(1024*1024)) }
|