about summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
authorLukas Kalbertodt <lukas.kalbertodt@gmail.com>2018-05-06 13:46:20 +0200
committerLukas Kalbertodt <lukas.kalbertodt@gmail.com>2018-05-06 13:46:20 +0200
commit9eeb13fdd1c10de7f489e7fc910686c6d492398e (patch)
tree72a400ad9e6051dd3e5305d954dc76b6b1204202 /src/rustllvm/RustWrapper.cpp
parent6f721f54c6fb1de9cf00eb9d2d050f818c882871 (diff)
downloadrust-9eeb13fdd1c10de7f489e7fc910686c6d492398e.tar.gz
rust-9eeb13fdd1c10de7f489e7fc910686c6d492398e.zip
Improve `Debug` impl of `core::time::Duration`
Prior to this, Duration simply derived Debug. Since Duration doesn't
implement `Display`, the only way to inspect its value is to use
`Debug`. Unfortunately, the derived `Debug` impl is far from optimal
for humans. In many cases, Durations are used for some quick'n'dirty
benchmarking (or in general: measuring the time of some code). Correctly
understanding the output of Duration's Debug impl is not easy (e.g.
is "{ secs: 0, nanos: 968360102 }" or "{ secs: 0, nanos 98507324 }"
shorter?).

This commit replaces the derived impl with a manual one. It prints
the duration as seconds (i.e. "3.1803s") if the duration is longer than
a second, otherwise it prints it in either ms, µs or ns (depending on
the duration's length). This already helps readability a lot and it
never omits information that is stored.

This `Debug` impl does *not* respect the following formatting parameters:

- fill/align/padding: difficult to implement, probably not worth it
- alternate # flag: not clear what this should do
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions