shirou / gopsutil

psutil for golang
Other
10.36k stars 1.57k forks source link

[host]: add EnableBootTimeCache function #1579

Closed shirou closed 6 months ago

shirou commented 6 months ago

This PR introduce host.EnableBootTimeCache to enable caching about BootTime. This may fix some of issues about CPU usage and performance.

% go test -bench . -benchmem
goos: linux
goarch: amd64
pkg: github.com/shirou/gopsutil/v3/host
cpu: AMD Ryzen 7 5800HS with Radeon Graphics
BenchmarkBootTimeWithCache-4            470418906                2.446 ns/op           0 B/op          0 allocs/op
BenchmarkBootTimeWithoutCache-4            55986             20535 ns/op            9920 B/op         24 allocs/op