13#if __cplusplus >= 202002L
16 static std::atomic<bool>
24 std::ifstream file(
"/sys/devices/system/cpu/cpu0/cache/index2/size");
28 std::getline(file, size_str);
32 char unit = size_str.back();
34 unsigned long cache_size = std::stoul(size_str);
42 cache_size *= 1024 * 1024;
50#elif defined(_WIN32) || defined(_WIN64)
64#if __cplusplus >= 202002L
67 static bool do_benchmarks =
false;
73 static std::deque<benchmark_pair> registered_benchmarks = {};
74 return registered_benchmarks;
79#if __cplusplus >= 202002L
82 static int num_iterations_benchmark = 100000;
83 return num_iterations_benchmark;
89 return benchmarks.size();
94#if __cplusplus >= 202002L
97 static bool run_one_benchmark =
false;
98 return run_one_benchmark;
103 static std::string one_benchmark =
"";
104 return one_benchmark;
109 static std::ofstream output;
116 save_to_file_ref = save_to_file;
122 output_dir_ref = std::ofstream(output_dir);
123 if (!output_dir_ref.is_open())
126 std::cout <<
"Could not open file " << output_dir <<
"\n";
129 output_dir_ref <<
"name,space,min,max,median,mean,sd,q1,q3\n";
135 benchmarks.push_back({name, benchmark});
141 do_benchmarks_ref = do_benchmarks;
147 num_iterations_benchmark = num_iterations;
153 run_one_benchmark_ref = run_one_benchmark;
159 one_benchmark_ref = one_benchmark;
165 if (bigger_than_cachesize == 0)
168 p =
new long[bigger_than_cachesize];
176 for (
size_t i = 0; i < bigger_than_cachesize; i++)
190 std::cout <<
"Running benchmark: " << benchmark.first <<
"\n";
191 std::cout << std::flush;
198 std::cout << std::flush;
200 benchmark.second(benchmark.first);
202 if (bigger_than_cachesize != 0)
int & get_num_iterations_benchmark()
bool & get_do_benchmarks()
void set_save_file(const std::filesystem::path &save_to_file_path)
void set_num_iterations_benchmark(int num_iterations_benchmark)
bool & get_run_one_benchmark()
void set_save_to_file(bool save_to_file)
std::atomic< bool > & get_verbose()
void set_one_benchmark(const std::string &one_benchmark)
std::ofstream & get_save_file()
void set_do_benchmarks(bool do_benchmarks)
void add_benchmark(const std::string &name, benchmark_function benchmark)
unsigned long get_num_benchmarks()
std::atomic< bool > & get_save_to_file()
std::string & get_one_benchmark()
unsigned long get_cache_l3_size()
std::function< void(std::string)> benchmark_function
std::deque< benchmark_pair > & get_benchmarks()
void set_run_one_benchmark(bool run_one_benchmark)
std::mutex & get_stream_mutex()