Skip to content

Commit

Permalink
Add parameter for benchmark duration
Browse files Browse the repository at this point in the history
  • Loading branch information
elsid authored and thed636 committed Apr 26, 2020
1 parent 7bba6fb commit 2425d5d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions benchmarks/performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ std::istream& operator >>(std::istream& stream, query_type& value) {
struct benchmark_params {
std::string conn_string;
::query_type query_type = ::query_type::simple;
std::chrono::steady_clock::duration duration;
std::size_t coroutines = 0;
std::size_t threads_number = 0;
std::size_t queue_capacity = 0;
Expand Down Expand Up @@ -120,7 +121,7 @@ benchmark_report reopen_connection(const benchmark_params& params, Query query)
report.query = ozo::to_const_char(ozo::get_text(query));
report.parse_result = parse_result;

benchmark_t benchmark(1);
benchmark_t benchmark(1, params.duration);
benchmark.set_print_progress(params.verbose);

asio::io_context io(1);
Expand Down Expand Up @@ -155,7 +156,7 @@ benchmark_report reuse_connection(const benchmark_params& params, Query query) {
report.query = ozo::to_const_char(ozo::get_text(query));
report.parse_result = parse_result;

benchmark_t benchmark(1);
benchmark_t benchmark(1, params.duration);
benchmark.set_print_progress(params.verbose);

asio::io_context io(1);
Expand Down Expand Up @@ -193,7 +194,7 @@ benchmark_report use_connection_pool(const benchmark_params& params, Query query
report.queue_capacity = params.queue_capacity;
report.parse_result = parse_result;

benchmark_t benchmark(params.coroutines);
benchmark_t benchmark(params.coroutines, params.duration);
benchmark.set_print_progress(params.verbose);

asio::io_context io(1);
Expand Down Expand Up @@ -246,7 +247,7 @@ benchmark_report use_connection_pool_mult_threads(const benchmark_params& params
report.connections = params.connections;
report.parse_result = parse_result;

benchmark_t benchmark(params.coroutines * params.threads_number);
benchmark_t benchmark(params.coroutines * params.threads_number, params.duration);
benchmark.set_print_progress(params.verbose);

const ozo::connection_info connection_info(params.conn_string);
Expand Down Expand Up @@ -393,6 +394,7 @@ int main(int argc, char **argv) {
("connections", po::value<std::size_t>(), "number of parallel coroutines (default: equal to coroutines + 1)")
("parse,p", "parse query result")
("verbose,v", "use verbose output")
("duration,d", po::value<std::uint64_t>()->default_value(31), "benchmark duration in seconds")
;

po::variables_map variables;
Expand Down Expand Up @@ -424,6 +426,7 @@ int main(int argc, char **argv) {
}
params.parse_result = variables.count("parse") > 0;
params.verbose = variables.count("verbose") > 0;
params.duration = std::chrono::seconds(variables.at("duration").as<std::uint64_t>());

const auto report = run_benchmark(name, params);

Expand Down

0 comments on commit 2425d5d

Please sign in to comment.