代码拉取完成,页面将自动刷新
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()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。