timer.cpp: use units like 'ms', etc. vs. "millis"

Change wording and omit '.00' decimal points in times
This commit is contained in:
Aaron Gyes 2020-02-12 01:37:57 -08:00
parent d659ee336d
commit c01356ddd1
2 changed files with 21 additions and 20 deletions

View File

@ -8,6 +8,7 @@
#include <algorithm> #include <algorithm>
#include <cerrno> #include <cerrno>
#include <chrono> #include <chrono>
#include <cmath>
#include <cstddef> #include <cstddef>
#include <ctime> #include <ctime>
@ -128,13 +129,13 @@ wcstring timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2,
auto unit_short_name = [](tunit unit) { auto unit_short_name = [](tunit unit) {
switch (unit) { switch (unit) {
case tunit::minutes: case tunit::minutes:
return "mins"; return "min";
case tunit::seconds: case tunit::seconds:
return "secs"; return "sec";
case tunit::milliseconds: case tunit::milliseconds:
return "millis"; return "ms";
case tunit::microseconds: case tunit::microseconds:
return "micros"; return "\u03BCs";
} }
// GCC does not recognize the exhaustive switch above // GCC does not recognize the exhaustive switch above
return ""; return "";
@ -152,7 +153,7 @@ wcstring timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2,
return micros / 1.0; return micros / 1.0;
} }
// GCC does not recognize the exhaustive switch above // GCC does not recognize the exhaustive switch above
return 0.0; return std::nan("");
}; };
auto wall_unit = get_unit(net_wall_micros); auto wall_unit = get_unit(net_wall_micros);
@ -165,9 +166,9 @@ wcstring timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2,
if (!verbose) { if (!verbose) {
append_format(output, append_format(output,
L"\n_______________________________" L"\n_______________________________"
L"\nExecuted in %6.2F %s" L"\nDuration\t%6.3G %s:"
L"\n usr time %6.2F %s" L"\n user time\t%6.3G %s"
L"\n sys time %6.2F %s" L"\n kernel time\t%6.3G %s"
L"\n", L"\n",
wall_time, unit_name(wall_unit), usr_time, unit_name(cpu_unit), sys_time, wall_time, unit_name(wall_unit), usr_time, unit_name(cpu_unit), sys_time,
unit_name(cpu_unit)); unit_name(cpu_unit));
@ -181,9 +182,9 @@ wcstring timer_snapshot_t::print_delta(timer_snapshot_t t1, timer_snapshot_t t2,
append_format(output, append_format(output,
L"\n________________________________________________________" L"\n________________________________________________________"
L"\nExecuted in %6.2F %s %*s %*s " L"\nDuration %6.3G %s %*s %*s "
L"\n usr time %6.2F %s %6.2F %s %6.2F %s " L"\n user time %6.3G %s %6.3G %s %6.3G %s "
L"\n sys time %6.2F %s %6.2F %s %6.2F %s " L"\n kernel time %6.3G %s %6.3G %s %6.3G %s "
L"\n", L"\n",
wall_time, unit_short_name(wall_unit), strlen(unit_short_name(wall_unit)) - 1, wall_time, unit_short_name(wall_unit), strlen(unit_short_name(wall_unit)) - 1,
"fish", strlen(unit_short_name(fish_unit)) - 1, "external", usr_time, "fish", strlen(unit_short_name(fish_unit)) - 1, "external", usr_time,

View File

@ -4,9 +4,9 @@ time sleep 0
# These are a tad awkward because it picks the correct unit and adapts whitespace. # These are a tad awkward because it picks the correct unit and adapts whitespace.
# The idea is that it's a table. # The idea is that it's a table.
#CHECKERR: ________________________________________________________ #CHECKERR: ________________________________________________________
#CHECKERR: Executed in {{[\d,.\s]*}} {{millis|micros|secs}} {{\s*}}fish {{\s*}}external #CHECKERR: Duration {{[\d,.\s]*}} {{ms|μs|sec}} {{\s*}}fish {{\s*}}external
#CHECKERR: usr time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} #CHECKERR: user time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}}
#CHECKERR: sys time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} #CHECKERR: kernel time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}}
time for i in (seq 1 2) time for i in (seq 1 2)
echo banana echo banana
end end
@ -14,17 +14,17 @@ end
#CHECK: banana #CHECK: banana
#CHECK: banana #CHECK: banana
#CHECKERR: ________________________________________________________ #CHECKERR: ________________________________________________________
#CHECKERR: Executed in {{[\d,.\s]*}} {{millis|micros|secs}} {{\s*}}fish {{\s*}}external #CHECKERR: Duration {{[\d,.\s]*}} {{ms|μs|sec}} {{\s*}}fish {{\s*}}external
#CHECKERR: usr time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} #CHECKERR: user time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}}
#CHECKERR: sys time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} #CHECKERR: kernel time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}}
# Make sure we're not double-parsing # Make sure we're not double-parsing
time echo 'foo -s bar' time echo 'foo -s bar'
#CHECK: foo -s bar #CHECK: foo -s bar
#CHECKERR: ________________________________________________________ #CHECKERR: ________________________________________________________
#CHECKERR: Executed in {{[\d,.\s]*}} {{millis|micros|secs}} {{\s*}}fish {{\s*}}external #CHECKERR: Duration {{[\d,.\s]*}} {{ms|μs|sec}} {{\s*}}fish {{\s*}}external
#CHECKERR: usr time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} #CHECKERR: user time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}}
#CHECKERR: sys time {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} {{[\d,.\s]*}} {{millis|micros|secs}} #CHECKERR: kernel time {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}} {{[\d,.\s]*}} {{ms|μs|sec}}
true && time a=b not builtin true | true true && time a=b not builtin true | true
#CHECKERR: ___{{.*}} #CHECKERR: ___{{.*}}