45#if defined(TIMEMORY_UNIX)
49#if defined(TIMEMORY_WINDOWS)
51# if !defined(NOMINMAX)
54# if !defined(WIN32_LEAN_AND_MEAN)
55# define WIN32_LEAN_AND_MEAN
59# include <sysinfoapi.h>
70static constexpr int64_t nsec = 1;
71static constexpr int64_t usec = 1000 * nsec;
72static constexpr int64_t msec = 1000 * usec;
73static constexpr int64_t csec = 10 * msec;
74static constexpr int64_t dsec = 10 * csec;
75static constexpr int64_t sec = 10 * dsec;
76static constexpr int64_t minute = 60 * sec;
77static constexpr int64_t hour = 60 * minute;
79static constexpr int64_t
byte = 1;
80static constexpr int64_t kilobyte = 1000 * byte;
81static constexpr int64_t megabyte = 1000 * kilobyte;
82static constexpr int64_t gigabyte = 1000 * megabyte;
83static constexpr int64_t terabyte = 1000 * gigabyte;
84static constexpr int64_t petabyte = 1000 * terabyte;
86static constexpr int64_t kibibyte = 1024 * byte;
87static constexpr int64_t mebibyte = 1024 * kibibyte;
88static constexpr int64_t gibibyte = 1024 * mebibyte;
89static constexpr int64_t tebibyte = 1024 * gibibyte;
90static constexpr int64_t pebibyte = 1024 * tebibyte;
92static constexpr int64_t B = 1;
93static constexpr int64_t KB = 1000 * B;
94static constexpr int64_t MB = 1000 * KB;
95static constexpr int64_t GB = 1000 * MB;
96static constexpr int64_t TB = 1000 * GB;
97static constexpr int64_t PB = 1000 * TB;
99static constexpr int64_t Bi = 1;
100static constexpr int64_t KiB = 1024 * Bi;
101static constexpr int64_t MiB = 1024 * KiB;
102static constexpr int64_t GiB = 1024 * MiB;
103static constexpr int64_t TiB = 1024 * GiB;
104static constexpr int64_t PiB = 1024 * TiB;
106#if defined(TIMEMORY_LINUX)
111 static auto _pagesz = sysconf(_SC_PAGESIZE);
114const int64_t clocks_per_sec = sysconf(_SC_CLK_TCK);
116#elif defined(TIMEMORY_MACOS)
121 static auto _pagesz = getpagesize();
124const int64_t clocks_per_sec = sysconf(_SC_CLK_TCK);
126#elif defined(TIMEMORY_WINDOWS)
131 static auto _pagesz = []() {
133 GetSystemInfo(&sysInfo);
134 return sysInfo.dwPageSize;
138const int64_t clocks_per_sec = CLOCKS_PER_SEC;
150 case nsec: _sunit =
"nsec";
break;
151 case usec: _sunit =
"usec";
break;
152 case msec: _sunit =
"msec";
break;
153 case csec: _sunit =
"csec";
break;
154 case dsec: _sunit =
"dsec";
break;
155 case sec: _sunit =
"sec";
break;
156 default: _sunit =
"UNK";
break;
169 case byte: _sunit =
"B";
break;
170 case kilobyte: _sunit =
"KB";
break;
171 case megabyte: _sunit =
"MB";
break;
172 case gigabyte: _sunit =
"GB";
break;
173 case terabyte: _sunit =
"TB";
break;
174 case petabyte: _sunit =
"PB";
break;
175 case kibibyte: _sunit =
"KiB";
break;
176 case mebibyte: _sunit =
"MiB";
break;
177 case gibibyte: _sunit =
"GiB";
break;
178 case tebibyte: _sunit =
"TiB";
break;
179 case pebibyte: _sunit =
"PiB";
break;
180 default: _sunit =
"UNK";
break;
187inline std::tuple<std::string, int64_t>
191 using return_type = std::tuple<string_t, int64_t>;
192 using inner_t = std::tuple<string_t, string_t, int64_t>;
194 if(_unit.length() == 0)
195 return return_type{
"MB", tim::units::megabyte };
197 for(
auto& itr : _unit)
200 for(
const auto& itr : { inner_t{
"byte",
"b", tim::units::byte },
201 inner_t{
"kilobyte",
"kb", tim::units::kilobyte },
202 inner_t{
"megabyte",
"mb", tim::units::megabyte },
203 inner_t{
"gigabyte",
"gb", tim::units::gigabyte },
204 inner_t{
"terabyte",
"tb", tim::units::terabyte },
205 inner_t{
"petabyte",
"pb", tim::units::petabyte },
206 inner_t{
"kibibyte",
"kib", tim::units::KiB },
207 inner_t{
"mebibyte",
"mib", tim::units::MiB },
208 inner_t{
"gibibyte",
"gib", tim::units::GiB },
209 inner_t{
"tebibyte",
"tib", tim::units::TiB },
210 inner_t{
"pebibyte",
"pib", tim::units::PiB } })
212 if(_unit == std::get<0>(itr) || _unit == std::get<1>(itr))
214 if(std::get<0>(itr) ==
"byte")
215 return return_type(std::get<0>(itr), std::get<2>(itr));
216 return return_type(std::get<1>(itr), std::get<2>(itr));
220 std::cerr <<
"Warning!! No memory unit matching \"" << _unit <<
"\". Using default..."
223 return return_type{
"MB", tim::units::megabyte };
228inline std::tuple<std::string, int64_t>
232 using strset_t = std::unordered_set<string_t>;
233 using return_type = std::tuple<string_t, int64_t>;
234 using inner_t = std::tuple<string_t, strset_t, int64_t>;
236 if(_unit.length() == 0)
237 return return_type{
"sec", tim::units::sec };
239 for(
auto& itr : _unit)
242 for(
const auto& itr :
243 { inner_t{
"nsec", strset_t{
"ns",
"nanosecond",
"nanoseconds" },
245 inner_t{
"usec", strset_t{
"us",
"microsecond",
"microseconds" },
247 inner_t{
"msec", strset_t{
"ms",
"millisecond",
"milliseconds" },
249 inner_t{
"csec", strset_t{
"cs",
"centisecond",
"centiseconds" },
251 inner_t{
"dsec", strset_t{
"ds",
"decisecond",
"deciseconds" },
253 inner_t{
"sec", strset_t{
"s",
"second",
"seconds" }, tim::units::sec },
254 inner_t{
"min", strset_t{
"minute",
"minutes" }, tim::units::minute },
255 inner_t{
"hr", strset_t{
"hr",
"hour",
"hours" }, tim::units::hour } })
257 if(_unit == std::get<0>(itr) ||
258 std::get<1>(itr).find(_unit) != std::get<1>(itr).
end())
260 return return_type{ std::get<0>(itr), std::get<2>(itr) };
264 std::cerr <<
"Warning!! No timing unit matching \"" << _unit <<
"\". Using default..."
267 return return_type{
"sec", tim::units::sec };
std::tuple< std::string, int64_t > get_timing_unit(std::string _unit)
std::string mem_repr(int64_t _unit)
std::string time_repr(int64_t _unit)
std::tuple< std::string, int64_t > get_memory_unit(std::string _unit)
tim::mpl::apply< std::string > string