Use FixedDouble.

GitOrigin-RevId: f39998443780a33cd892ecc9fec8b9d666a82489
This commit is contained in:
levlam 2018-02-11 15:41:23 +03:00
parent 13def6a897
commit b6e6eac530
3 changed files with 14 additions and 8 deletions

View File

@ -9,6 +9,7 @@
#include "td/utils/format.h"
#include "td/utils/logging.h"
#include "td/utils/port/Clocks.h"
#include "td/utils/StringBuilder.h"
#include <cmath>
#include <tuple>
@ -110,12 +111,18 @@ inline void bench(Benchmark &b, double max_time = 1.0) {
max_pass_time = pass_time;
}
}
double avg = sum / pass_cnt;
double d = sqrt(square_sum / pass_cnt - avg * avg);
double average = sum / pass_cnt;
double d = sqrt(square_sum / pass_cnt - average * average);
LOG(ERROR, "Bench [%40s]:\t%.3lf[%.3lf-%.3lf] ops/sec,\t", b.get_description().c_str(), avg, min_pass_time,
max_pass_time)
<< format::as_time(1 / avg) << (PSLICE(" [d = %.6lf]", d));
auto description = b.get_description();
std::string pad;
if (description.size() < 40) {
pad = std::string(40 - description.size(), ' ');
}
LOG(ERROR) << "Bench [" << pad << description << "]: " << StringBuilder::FixedDouble(average, 3) << '['
<< StringBuilder::FixedDouble(min_pass_time, 3) << '-' << StringBuilder::FixedDouble(max_pass_time, 3)
<< "] ops/sec,\t" << format::as_time(1 / average) << " [d = " << StringBuilder::FixedDouble(d, 6) << ']';
}
inline void bench(Benchmark &&b, double max_time = 1.0) {

View File

@ -175,7 +175,7 @@ inline StringBuilder &operator<<(StringBuilder &logger, Time t) {
while (i + 1 < durations_n && t.seconds_ > 10 * durations[i + 1].value) {
i++;
}
logger.printf("%.1lf%s", t.seconds_ / durations[i].value, durations[i].name);
logger << StringBuilder::FixedDouble(t.seconds_ / durations[i].value, 1) << durations[i].name;
return logger;
}

View File

@ -61,8 +61,7 @@ Logger::Logger(LogInterface &log, int log_level, Slice file_name, int line_num,
if (tid != -1) {
printf("[t%2d]", tid);
}
printf("[%.9lf]", Clocks::system());
(*this) << "[" << file_name << ":" << line_num << "]";
(*this) << StringBuilder::FixedDouble(Clocks::system(), 9) << "[" << file_name << ":" << line_num << "]";
if (tag_ != nullptr && *tag_) {
(*this) << "[#" << Slice(tag_) << "]";
}