MCPcopy Create free account
hub / github.com/HO-COOH/FastCopy / Speed

Class Speed

FastCopy/ReadableUnitConverter.h:47–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45 };
46
47 struct Speed
48 {
49 static auto BytesPerSec(size_t bytes, std::chrono::nanoseconds duration)
50 {
51 return duration.count() == 0 ? 0 : bytes / (static_cast<double>(duration.count()) / 1e9);
52 }
53
54 template<typename Char>
55 static auto ToString(size_t bytes, std::chrono::nanoseconds duration)
56 {
57 if (duration.count() == 0)
58 {
59 if constexpr (std::is_same_v<Char, char>)
60 {
61 return decltype(Size::ToString<char>(1)){"---"};
62 }
63 else
64 {
65 return decltype(Size::ToString<wchar_t>(1)) {L"---"};
66 }
67 }
68 return Size::ToString<Char>(BytesPerSec(bytes, duration)) + L"/s";
69 }
70
71 template<typename Char>
72 static auto ToString(double bytesPerSec)
73 {
74 if (bytesPerSec == 0)
75 {
76 if constexpr (std::is_same_v<Char, char>)
77 {
78 return decltype(Size::ToString<char>(1)){"---"};
79 }
80 else
81 {
82 return decltype(Size::ToString<wchar_t>(1)) {L"---"};
83 }
84 }
85 return Size::ToString<Char>(bytesPerSec) + L"/s";
86 }
87 };
88}
89

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected