1 Star 0 Fork 0

coodder / unipdf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
memory_measure.go 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
jhonm 提交于 2023-08-07 15:31 . init
package e2etest
import (
"fmt"
"runtime"
"strings"
"time"
)
type memoryMeasure struct {
start runtime.MemStats
startTime time.Time
end runtime.MemStats
endTime time.Time
}
func startMemoryMeasurement() memoryMeasure {
var m memoryMeasure
runtime.ReadMemStats(&m.start)
m.startTime = time.Now().UTC()
return m
}
// Stops finishes the measurement.
func (m *memoryMeasure) Stop() {
runtime.ReadMemStats(&m.end)
m.endTime = time.Now().UTC()
}
func (m memoryMeasure) Summary() string {
alloc := float64(m.end.TotalAlloc) - float64(m.start.TotalAlloc)
mallocs := int64(m.end.Mallocs) - int64(m.start.Mallocs)
frees := int64(m.end.Frees) - int64(m.start.Frees)
duration := m.endTime.Sub(m.startTime)
var b strings.Builder
b.WriteString(fmt.Sprintf("Duration: %.2f seconds\n", duration.Seconds()))
b.WriteString(fmt.Sprintf("Alloc: %.2f MB\n", alloc/1024.0/1024.0))
b.WriteString(fmt.Sprintf("Mallocs: %d\n", mallocs))
b.WriteString(fmt.Sprintf("Frees: %d\n", frees))
return b.String()
}
Go
1
https://gitee.com/coodder/unipdf.git
git@gitee.com:coodder/unipdf.git
coodder
unipdf
unipdf
v1.2.0

搜索帮助