1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:44:58 +00:00

Utilities: Store per-benchmark timeout in AK::Time rather than integer

Integer seconds are cool, but the comparison is a lot easier to
understand when stored as an AK::Time, and converted from_seconds()
after parsing the timeout from the command line.
This commit is contained in:
Andrew Kaster 2023-01-01 22:48:39 -07:00 committed by Linus Groh
parent 4e7bdcfeea
commit 48bf0b1408

View file

@ -43,8 +43,10 @@ static ErrorOr<Result> benchmark(DeprecatedString const& filename, int file_size
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
using namespace AK::TimeLiterals;
DeprecatedString directory = ".";
int time_per_benchmark = 10;
i64 time_per_benchmark_sec = 10;
Vector<size_t> file_sizes;
Vector<size_t> block_sizes;
bool allow_cache = false;
@ -52,11 +54,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Core::ArgsParser args_parser;
args_parser.add_option(allow_cache, "Allow using disk cache", "cache", 'c');
args_parser.add_option(directory, "Path to a directory where we can store the disk benchmark temp file", "directory", 'd', "directory");
args_parser.add_option(time_per_benchmark, "Time elapsed per benchmark", "time-per-benchmark", 't', "time-per-benchmark");
args_parser.add_option(time_per_benchmark_sec, "Time elapsed per benchmark (seconds)", "time-per-benchmark", 't', "time-per-benchmark");
args_parser.add_option(file_sizes, "A comma-separated list of file sizes", "file-size", 'f', "file-size");
args_parser.add_option(block_sizes, "A comma-separated list of block sizes", "block-size", 'b', "block-size");
args_parser.parse(arguments);
Time const time_per_benchmark = Time::from_seconds(time_per_benchmark_sec);
if (file_sizes.size() == 0) {
file_sizes = { 131072, 262144, 524288, 1048576, 5242880 };
}
@ -82,7 +86,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
outln("Running: file_size={} block_size={}", file_size, block_size);
auto timer = Core::ElapsedTimer::start_new();
while (timer.elapsed() < time_per_benchmark * 1000) {
while (timer.elapsed_time() < time_per_benchmark) {
out(".");
fflush(stdout);
auto result = TRY(benchmark(filename, file_size, buffer_result.value(), allow_cache));