21 #ifndef SNABSUITE_COMMON_BENCHMARK_HPP 22 #define SNABSUITE_COMMON_BENCHMARK_HPP 24 #include <cypress/cypress.hpp> 32 using cypress::global_logger;
40 std::string m_backend;
42 cypress::Json results;
47 std::string convert_time(
int value)
50 return '0' + std::to_string(value);
52 return std::to_string(value);
58 std::string timestamp()
60 auto ltime = time(NULL);
61 auto Tm = localtime(<ime);
62 return std::to_string(1900 + Tm->tm_year) +
"-" +
63 convert_time(Tm->tm_mon) +
"-" + convert_time(Tm->tm_mday) +
64 "T" + convert_time(Tm->tm_hour) +
":" +
65 convert_time(Tm->tm_min) +
":" + convert_time(Tm->tm_sec);
71 std::vector<std::string> bench_index_str{
"Single Core/Smallest Network",
72 "Single Chip",
"Small System",
78 size_t check_for_repeat(
const cypress::Json &config)
80 if (config.count(
"repeat") > 0) {
81 size_t rep = config[
"repeat"].get<
size_t>();
93 cypress::Json merge_repeat_results(
94 const std::vector<cypress::Json> &results);
106 for (
auto i : snab_vec) {
109 global_logger().info(
"SNABSuite",
110 "Executing " +
i->snab_name());
111 size_t repeat = check_for_repeat(
i->get_config());
115 results.push_back({{
"model",
i->snab_name()},
116 {
"timestamp", timestamp()},
118 {
"results",
i->evaluate_json()}});
121 std::vector<cypress::Json> repeat_results;
123 for (
size_t j = 0; j < repeat; j++) {
125 repeat_results.push_back(
i->evaluate_json());
128 {{
"model",
i->snab_name()},
129 {
"timestamp", timestamp()},
131 {
"results", merge_repeat_results(repeat_results)}});
135 std::cout << results.dump(4) << std::endl;
139 (backend +
"_" + std::to_string(
bench_index) +
".json").c_str(),
141 if (results.size() > 1) {
142 file << results.dump(4) << std::endl;
145 file << results[0].dump(4) << std::endl;
std::vector< std::shared_ptr< SNABBase > > snab_registry(std::string backend, size_t bench_index)
BenchmarkExec(std::string backend, std::string benchmark="all", size_t bench_index=0)