From: Jacob Lifshay Date: Wed, 27 Jul 2022 07:29:09 +0000 (-0700) Subject: add --target-duration option X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9132db285826cacff221f3bf8538a03b2b48ef8f;p=benchmarks.git add --target-duration option --- diff --git a/src/harness.cpp b/src/harness.cpp index e6fbda3..68d33a1 100644 --- a/src/harness.cpp +++ b/src/harness.cpp @@ -289,7 +289,13 @@ std::shared_ptr BenchHarnessBase::base_run( { total_elapsed += i; } - auto target_average_elapsed = std::chrono::milliseconds(500); + std::chrono::duration target_average_elapsed = + std::chrono::milliseconds(500); + if (config.target_duration) + { + target_average_elapsed = + std::chrono::duration(*config.target_duration); + } if (total_elapsed > thread_count * target_average_elapsed || iteration_count >= (1ULL << 63)) { diff --git a/src/harness.h b/src/harness.h index b9ab39d..9c43cdd 100644 --- a/src/harness.h +++ b/src/harness.h @@ -15,6 +15,7 @@ struct Config final { std::optional thread_count; std::optional iteration_count; + std::optional target_duration; std::uint32_t log2_memory_location_count = 0; std::uint32_t log2_stride = 0; static constexpr std::uint32_t max_sum_log2_mem_loc_count_and_stride = 28; @@ -24,6 +25,7 @@ struct Config final return JsonValue::Object{ {"thread_count", thread_count}, {"iteration_count", iteration_count}, + {"target_duration", target_duration}, {"log2_memory_location_count", log2_memory_location_count}, {"log2_stride", log2_stride}, {"use_json", use_json}, diff --git a/src/main.cpp b/src/main.cpp index f9bde51..c49029f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -390,6 +391,35 @@ class OptionsParser final i_value.emplace(); this->parse_int(value, i_value.value(), limits); } + template + std::enable_if_t, void> parse_float( + std::optional value, Float &f_value) + { + f_value = Float(); + if (!value) + { + help_and_exit("missing value for ", current_option()); + } + auto str = *value; + std::istringstream is{std::string(str)}; + if (!(is >> f_value)) + { + help_and_exit("invalid value for: ", current_option()); + } + } + template + std::enable_if_t, void> parse_float( + std::optional value, std::optional &f_value, + bool required = true) + { + if (!required && !value) + { + f_value = std::nullopt; + return; + } + f_value.emplace(); + this->parse_float(value, f_value.value()); + } }; inline std::vector Options::parse( @@ -479,6 +509,23 @@ int main(int, char **argv) config.use_json = true; json_pretty = true; }}, + Option{.short_name = 'd', + .long_name = "target-duration", + .description = + "target duration for a single benchmark in seconds", + .value_kind = OptionValueKind::Required, + .parse_value = + [&](OptionsParser &parser, auto value) { + parser.parse_float(value, config.target_duration); + if (config.target_duration && + (!std::isfinite(*config.target_duration) || + *config.target_duration < 0)) + { + parser.help_and_exit( + "value out of range: target-duration=", + *config.target_duration); + } + }}, }; OptionsParser parser(options, argv); auto args = parser.parse();