Memory usage optimization

This commit is contained in:
nuknal
2024-06-15 13:05:42 +08:00
parent 0c17fee9c7
commit 35bf364e97
7 changed files with 84 additions and 22 deletions

View File

@@ -1,5 +1,12 @@
package rrc
import (
"runtime"
"github.com/dustin/go-humanize"
log "github.com/sirupsen/logrus"
)
func searchVL(V []float64, Sik float64) int {
left, right := 0, len(V)-2
@@ -24,3 +31,16 @@ func searchVL(V []float64, Sik float64) int {
// Return -1 if no such position is found
return -1
}
var lastTotalFreed uint64
func printMemStats() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
log.Printf("[Memory] Alloc = %v TotalAlloc=%v Just Freed = %v Sys = %v NumGc=%v",
humanize.Bytes(m.Alloc),
humanize.Bytes(m.TotalAlloc),
humanize.Bytes(((m.TotalAlloc - m.Alloc) - lastTotalFreed)),
humanize.Bytes(m.Sys), m.NumGC)
lastTotalFreed = m.TotalAlloc - m.Alloc
}