{
total_elapsed += i;
}
- auto target_average_elapsed = std::chrono::milliseconds(500);
+ std::chrono::duration<double> target_average_elapsed =
+ std::chrono::milliseconds(500);
+ if (config.target_duration)
+ {
+ target_average_elapsed =
+ std::chrono::duration<double>(*config.target_duration);
+ }
if (total_elapsed > thread_count * target_average_elapsed ||
iteration_count >= (1ULL << 63))
{
{
std::optional<std::uint32_t> thread_count;
std::optional<std::uint64_t> iteration_count;
+ std::optional<double> 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;
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},
#include <map>
#include <optional>
#include <ostream>
+#include <sstream>
#include <string_view>
#include <system_error>
#include <type_traits>
i_value.emplace();
this->parse_int(value, i_value.value(), limits);
}
+ template <typename Float>
+ std::enable_if_t<std::is_floating_point_v<Float>, void> parse_float(
+ std::optional<std::string_view> 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 <typename Float>
+ std::enable_if_t<std::is_floating_point_v<Float>, void> parse_float(
+ std::optional<std::string_view> value, std::optional<Float> &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<std::string_view> Options::parse(
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();