40 namespace timeit_detail
43 template<
typename TimeUnit>
51 template<
typename TimeUnit>
55 if constexpr (std::is_same<TimeUnit, std::chrono::hours>::value)
59 else if constexpr (std::is_same<TimeUnit, std::chrono::minutes>::value)
63 else if constexpr (std::is_same<TimeUnit, std::chrono::seconds>::value)
67 else if constexpr (std::is_same<TimeUnit, std::chrono::milliseconds>::value)
69 unit =
" milliseconds";
71 else if constexpr (std::is_same<TimeUnit, std::chrono::microseconds>::value)
73 unit =
" microseconds";
75 else if constexpr (std::is_same<TimeUnit, std::chrono::nanoseconds>::value)
77 unit =
" nanoseconds";
81 unit =
" time units of some sort";
84 os <<
"Timeit results:\n";
85 os <<
"\tmin: " << result.
min.count() << unit <<
"\n";
86 os <<
"\tmax: " << result.
max.count() << unit <<
"\n";
87 os <<
"\tmean: " << result.
mean.count() << unit <<
"\n";
103 template<
typename TimeUnit,
typename Function,
typename... Args>
104 timeit_detail::Result<TimeUnit>
110 for (
uint32 i = 0; i < numIterations; ++i)
119 using ResultType = std::invoke_result_t<Function, Args...>;
120 if constexpr (std::is_same_v<ResultType, void>)
122 function(std::forward<Args>(args)...);
127 [[maybe_unused]]
const ResultType functionResult = function(std::forward<Args&>(args)...);
132 result.mean = result.mean + elapsedTime;
133 result.min =
std::min(result.min, elapsedTime);
134 result.max =
std::max(result.max, elapsedTime);
137 result.mean = result.mean / numIterations;
A timer class for timing code execution.
Definition: Timer.hpp:45
std::ostream & operator<<(std::ostream &os, const Result< TimeUnit > result)
Definition: timeit.hpp:52
Definition: Utils/cube.hpp:33
timeit_detail::Result< TimeUnit > timeit(uint32 numIterations, PrintResults printResults, Function function, Args &&... args) noexcept
Definition: timeit.hpp:105
NdArray< dtype > min(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: min.hpp:44
PrintResults
Print Results boolean.
Definition: Enums.hpp:119
std::uint32_t uint32
Definition: Types.hpp:40
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:44
Result statistics of a timeit run.
Definition: timeit.hpp:45
TimeUnit max
Definition: timeit.hpp:47
TimeUnit mean
Definition: timeit.hpp:48
TimeUnit min
Definition: timeit.hpp:46