Skip to content
เข้าสู่ระบบ

Performance

Go เร็วอยู่แล้ว แต่ถ้ารู้วิธี optimize จะเร็วขึ้นอีกหลายเท่า

Profiling - หา Bottleneck ก่อน

Section titled “Profiling - หา Bottleneck ก่อน”

ก่อน optimize ต้องรู้ก่อนว่าช้าตรงไหน

Terminal window
# CPU profiling
go test -cpuprofile=cpu.prof -bench=.
go tool pprof cpu.prof
# Memory profiling
go test -memprofile=mem.prof -bench=.
go tool pprof mem.prof
# HTTP server profiling
import _ "net/http/pprof"
# แล้วเข้า http://localhost:6060/debug/pprof/

เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม

ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด