MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / HumanReadableNumBytes

Function HumanReadableNumBytes

tensorflow/core/lib/strings/numbers.cc:459–492  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

457}
458
459string HumanReadableNumBytes(int64 num_bytes) {
460 if (num_bytes == kint64min) {
461 // Special case for number with not representable negation.
462 return "-8E";
463 }
464
465 const char* neg_str = (num_bytes < 0) ? "-" : "";
466 if (num_bytes < 0) {
467 num_bytes = -num_bytes;
468 }
469
470 // Special case for bytes.
471 if (num_bytes < 1024) {
472 // No fractions for bytes.
473 char buf[8]; // Longest possible string is '-XXXXB'
474 snprintf(buf, sizeof(buf), "%s%lldB", neg_str,
475 static_cast<int64>(num_bytes));
476 return string(buf);
477 }
478
479 static const char units[] = "KMGTPE"; // int64 only goes up to E.
480 const char* unit = units;
481 while (num_bytes >= static_cast<int64>(1024) * 1024) {
482 num_bytes /= 1024;
483 ++unit;
484 CHECK(unit < units + TF_ARRAYSIZE(units));
485 }
486
487 // We use SI prefixes.
488 char buf[16];
489 snprintf(buf, sizeof(buf), ((*unit == 'K') ? "%s%.1f%ciB" : "%s%.2f%ciB"),
490 neg_str, num_bytes / 1024.0, *unit);
491 return string(buf);
492}
493
494string HumanReadableElapsedTime(double seconds) {
495 string human_readable;

Callers 15

TESTFunction · 0.70
ToStringMethod · 0.50
ToStringMethod · 0.50
CompressInstructionFunction · 0.50
RematerializeBestBlockFunction · 0.50
ComputePeakMemoryMethod · 0.50
RunMethod · 0.50
DefaultMemorySchedulerFunction · 0.50
DefaultModuleSchedulerFunction · 0.50
ToStringMethod · 0.50

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.56