MCPcopy Create free account
hub / github.com/catboost/catboost / THumanReadableDuration>

Method THumanReadableDuration>

util/stream/format.cpp:74–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72
73template <>
74void Out<NFormatPrivate::THumanReadableDuration>(IOutputStream& os, const NFormatPrivate::THumanReadableDuration& hr) {
75 TTempBuf buf;
76 TMemoryOutput ss(buf.Data(), buf.Size());
77
78 do {
79 ui64 microSeconds = hr.Value.MicroSeconds();
80 if (microSeconds < 1000) {
81 ss << microSeconds << "us";
82 break;
83 }
84 if (microSeconds < 1000 * 1000) {
85 NFormatPrivate::PrintDoubleShortly(ss, (double)microSeconds / 1000.0) << "ms";
86 break;
87 }
88
89 double seconds = (double)(hr.Value.MilliSeconds()) / 1000.0;
90 if (seconds < 60) {
91 NFormatPrivate::PrintDoubleShortly(ss, seconds) << 's';
92 break;
93 }
94
95 ui64 s = NFormatPrivate::Round(seconds * 1000 + 0.5) / 1000;
96
97 ui64 m = s / 60;
98 s = s % 60;
99
100 ui64 h = m / 60;
101 m = m % 60;
102
103 ui64 d = h / 24;
104 h = h % 24;
105
106 ui64 times[] = {d, h, m, s};
107 char names[] = {'d', 'h', 'm', 's'};
108 bool first = true;
109
110 for (size_t i = 0; i < Y_ARRAY_SIZE(times); ++i) {
111 if (times[i] > 0) {
112 if (!first) {
113 ss << ' ';
114 }
115 ss << times[i] << names[i];
116 first = false;
117 }
118 }
119 } while (false);
120
121 size_t written = buf.Size() - ss.Avail();
122 os.Write(buf.Data(), written);
123}
124
125void Time(IOutputStream& l) {
126 l << millisec();

Callers

nothing calls this directly

Calls 7

RoundFunction · 0.70
DataMethod · 0.45
SizeMethod · 0.45
MicroSecondsMethod · 0.45
MilliSecondsMethod · 0.45
AvailMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected