From 32b4470ea37f1e27b32947788a914a8161818ad3 Mon Sep 17 00:00:00 2001 From: Tobias Christiansen Date: Mon, 23 Aug 2021 23:30:36 +0200 Subject: [PATCH] Shell: Use new Statistics tool in 'time -n' command The new Statistics utility is now used when calling 'time -n' to get some more information of the timings. For now only the standard deviation is given in addition to the average. This commit completely undos #9645 because everything that touched moved into AK::Statistics. --- Userland/Shell/Builtin.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Userland/Shell/Builtin.cpp b/Userland/Shell/Builtin.cpp index 414e378eee7..1dbfa41af2e 100644 --- a/Userland/Shell/Builtin.cpp +++ b/Userland/Shell/Builtin.cpp @@ -9,6 +9,7 @@ #include "Shell/Formatter.h" #include #include +#include #include #include #include @@ -898,8 +899,7 @@ int Shell::builtin_time(int argc, const char** argv) auto commands = expand_aliases({ move(command) }); - Vector iteration_times; - iteration_times.ensure_capacity(number_of_iterations); + AK::Statistics iteration_times; int exit_code = 1; for (int i = 0; i < number_of_iterations; ++i) { @@ -909,25 +909,21 @@ int Shell::builtin_time(int argc, const char** argv) block_on_job(job); exit_code = job.exit_code(); } - iteration_times.unchecked_append(timer.elapsed()); + iteration_times.add(timer.elapsed()); } if (number_of_iterations == 1) { - warnln("Time: {} ms", iteration_times.first()); + warnln("Time: {} ms", iteration_times.values().first()); } else { - float total_time = 0; - for (auto time : iteration_times) - total_time += static_cast(time); - float average = total_time / number_of_iterations; - - float total_time_excluding_first = total_time - static_cast(iteration_times.first()); - float average_excluding_first = total_time_excluding_first / (number_of_iterations - 1); + AK::Statistics iteration_times_excluding_first; + for (size_t i = 1; i < iteration_times.size(); i++) + iteration_times_excluding_first.add(iteration_times.values()[i]); warnln("Timing report:"); warnln("=============="); warnln("Command: {}", String::join(' ', args)); - warnln("Average time: {} ms", average); - warnln("Excluding first: {} ms", average_excluding_first); + warnln("Average time: {:.2} ms (median: {}, stddev: {:.2})", iteration_times.average(), iteration_times.median(), iteration_times.standard_deviation()); + warnln("Excluding first: {:.2} ms (median: {}, stddev: {:.2})", iteration_times_excluding_first.average(), iteration_times_excluding_first.median(), iteration_times_excluding_first.standard_deviation()); } return exit_code;