MCPcopy
hub / github.com/nats-io/nats.go / HumanBytes

Function HumanBytes

bench/bench.go:323–339  ·  view source on GitHub ↗

HumanBytes formats bytes as a human readable string

(bytes float64, si bool)

Source from the content-addressed store, hash-verified

321
322// HumanBytes formats bytes as a human readable string
323func HumanBytes(bytes float64, si bool) string {
324 var base = 1024
325 pre := []string{"K", "M", "G", "T", "P", "E"}
326 var post = "B"
327 if si {
328 base = 1000
329 pre = []string{"k", "M", "G", "T", "P", "E"}
330 post = "iB"
331 }
332 if bytes < float64(base) {
333 return fmt.Sprintf("%.2f B", bytes)
334 }
335 exp := int(math.Log(bytes) / math.Log(float64(base)))
336 index := exp - 1
337 units := pre[index] + post
338 return fmt.Sprintf("%.2f %s", bytes/math.Pow(float64(base), float64(exp)), units)
339}
340
341// MsgsPerClient divides the number of messages by the number of clients and tries to distribute them as evenly as possible
342func MsgsPerClient(numMsgs, numClients int) []int {

Callers 1

StringMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected