25 #include <plf_nanotimer.h>
38 std::chrono::steady_clock::time_point t_start;
52 t_start = std::chrono::steady_clock::now();
66 auto t_end = std::chrono::steady_clock::now();
68 std::chrono::duration_cast<std::chrono::nanoseconds>(t_end - t_start).count());
80 return sham::format(
"{:.2f} {}s", res.value, res.prefix);
146 for (
u32 i = 0; i < relaunch; i++) {
220 for (
f64 i = start; i < end; i *= pow_exp) {
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
Class FunctionTimer measures the time it takes to execute a function.
f64 func_time_sec()
Returns the average time it takes to execute the function.
void time_func(Func &&f)
Measures the time it takes to execute a function.
Class Timer measures the time elapsed since the timer was started.
plf::nanotimer timer
Internal timer.
std::string get_time_str() const
Converts the stored nanosecond time to a string representation.
Timer()
Constructor, init nanosec to 0.
f64 elapsed_sec() const
Converts the stored nanosecond time to a floating point representation in seconds.
void start()
Starts the timer.
void stop()
Stops the timer and stores the elapsed time in nanoseconds.
f64 nanosec
Time in nanoseconds.
human_readable_t to_human_readable(double value)
Convert a raw value to a human-readable scaled form with an SI prefix.
namespace for basic c++ utilities
f64 timeitfor(Func &&f, f64 max_duration=1)
Measures the average time it takes to execute a function until a maximum duration is reached.
f64 timeit(Func &&f, u32 relaunch=1)
Measures the average time it takes to execute a function.
BenchmarkResult benchmark_pow_len(std::function< f64(u32)> func, u32 start, u32 end, f64 pow_exp)
Benchmark a function with input values following a power law.
Structure to store the results of a benchmark.
std::vector< f64 > counts
The counts of the benchmark.
std::vector< f64 > times
The times of the benchmark.