ente/utils/time.go

26 lines
449 B
Go
Raw Normal View History

2023-10-16 11:26:34 +00:00
package utils
import (
2023-10-16 17:56:31 +00:00
"fmt"
2023-10-16 11:26:34 +00:00
"log"
"time"
)
func TimeTrack(start time.Time, name string) {
elapsed := time.Since(start)
log.Printf("%s took %s", name, elapsed)
}
2023-10-16 17:56:31 +00:00
func ByteCountDecimal(b int64) string {
const unit = 1000
if b < unit {
return fmt.Sprintf("%d B", b)
}
div, exp := int64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %cB", float64(b)/float64(div), "kMGTPE"[exp])
}