mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-03-14 20:27:24 +00:00
Simplify benchmark_base::set_printer API.
Forcing the caller to use `std::ref` is gross.
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
#include <nvbench/device_manager.cuh>
|
||||
#include <nvbench/state.cuh>
|
||||
|
||||
#include <functional> // reference_wrapper
|
||||
#include <functional> // reference_wrapper, ref
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
@@ -153,9 +153,14 @@ struct benchmark_base
|
||||
|
||||
void run() { this->do_run(); }
|
||||
|
||||
void set_printer(optional_ref<nvbench::printer_base> printer)
|
||||
void set_printer(nvbench::printer_base& printer)
|
||||
{
|
||||
m_printer = printer;
|
||||
m_printer = std::ref(printer);
|
||||
}
|
||||
|
||||
void clear_printer()
|
||||
{
|
||||
m_printer = std::nullopt;
|
||||
}
|
||||
|
||||
[[nodiscard]] optional_ref<nvbench::printer_base> get_printer() const
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
#include <nvbench/option_parser.cuh>
|
||||
#include <nvbench/printer_base.cuh>
|
||||
|
||||
#include <functional> // std::ref
|
||||
#include <iostream>
|
||||
#include <optional> // std::nullopt
|
||||
|
||||
#define NVBENCH_MAIN \
|
||||
int main(int argc, char const *const *argv) \
|
||||
@@ -59,9 +57,9 @@
|
||||
auto &benchmarks = parser.get_benchmarks(); \
|
||||
for (auto &bench_ptr : benchmarks) \
|
||||
{ \
|
||||
bench_ptr->set_printer(std::ref(printer)); \
|
||||
bench_ptr->set_printer(printer); \
|
||||
bench_ptr->run(); \
|
||||
bench_ptr->set_printer(std::nullopt); \
|
||||
bench_ptr->clear_printer(); \
|
||||
} \
|
||||
printer.print_log_epilogue(); \
|
||||
printer.print_benchmark_results(benchmarks); \
|
||||
|
||||
Reference in New Issue
Block a user