From bcb65b90fe9bbf30553aef2ea627e0537ee62641 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sun, 14 Aug 2016 22:06:49 -0400 Subject: [PATCH] Give bssl speed proper arg parsing and a -timeout flag. I've found that changing the timeout to 10s rather than 1s gives much more stable numbers. BUG=82 Change-Id: Ie026bf808e8bf78b35925add69f84c3ff31c31ab Reviewed-on: https://boringssl-review.googlesource.com/10349 CQ-Verified: CQ bot account: commit-bot@chromium.org Commit-Queue: David Benjamin Commit-Queue: Adam Langley Reviewed-by: Adam Langley --- tool/speed.cc | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/tool/speed.cc b/tool/speed.cc index a8eb8bfa2..5b0792146 100644 --- a/tool/speed.cc +++ b/tool/speed.cc @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -87,10 +88,12 @@ static uint64_t time_now() { } #endif +static uint64_t g_timeout_seconds = 1; + static bool TimeFunction(TimeResults *results, std::function func) { - // kTotalMS is the total amount of time that we'll aim to measure a function + // total_us is the total amount of time that we'll aim to measure a function // for. - static const uint64_t kTotalUS = 1000000; + const uint64_t total_us = g_timeout_seconds * 1000000; uint64_t start = time_now(), now, delta; unsigned done = 0, iterations_between_time_checks; @@ -121,7 +124,7 @@ static bool TimeFunction(TimeResults *results, std::function func) { } now = time_now(); - if (now - start > kTotalUS) { + if (now - start > total_us) { break; } } @@ -543,14 +546,34 @@ static bool SpeedNewHope(const std::string &selected) { return true; } +static const struct argument kArguments[] = { + { + "-filter", kOptionalArgument, + "A filter on the speed tests to run", + }, + { + "-timeout", kOptionalArgument, + "The number of seconds to run each test for (default is 1)", + }, + { + "", kOptionalArgument, "", + }, +}; + bool Speed(const std::vector &args) { - std::string selected; - if (args.size() > 1) { - fprintf(stderr, "Usage: bssl speed [speed test selector, i.e. 'RNG']\n"); + std::map args_map; + if (!ParseKeyValueArguments(&args_map, args, kArguments)) { + PrintUsage(kArguments); return false; } - if (args.size() > 0) { - selected = args[0]; + + std::string selected; + if (args_map.count("-filter") != 0) { + selected = args_map["-filter"]; + } + + if (args_map.count("-timeout") != 0) { + g_timeout_seconds = atoi(args_map["-timeout"].c_str()); } RSA *key = RSA_private_key_from_bytes(kDERRSAPrivate2048,