Use fmt and std::from_chars to make convert integer to string and convert string to integer more efficient (#6361)

* [Optimize] optimize the speed of converting integer to string

* Use fmt and std::from_chars to make convert integer to string and convert string to integer more efficient

Co-authored-by: caiconghui <caiconghui@xiaomi.com>
This commit is contained in:
caiconghui
2021-08-04 10:55:19 +08:00
committed by GitHub
parent 16bc5fa585
commit d1007afe80
11 changed files with 71 additions and 123 deletions

View File

@ -55,18 +55,11 @@ uint24_t timestamp_from_date(const std::string& date_str) {
}
std::string time_str_from_double(double time) {
std::stringstream time_ss;
if (time < 0) {
time_ss << "-";
time = -time;
return fmt::format("-{:02d}:{:02d}:{:02d}", (int64_t)(time / 60 / 60), ((int64_t)(time / 60)) % 60, ((int64_t)time) % 60);
}
int64_t hour = time / 60 / 60;
int minute = ((int64_t)(time / 60)) % 60;
int second = ((int64_t)time) % 60;
time_ss << std::setw(2) << std::setfill('0') << hour << ":" << std::setw(2) << std::setfill('0')
<< minute << ":" << std::setw(2) << std::setfill('0') << second;
return time_ss.str();
return fmt::format("{:02d}:{:02d}:{:02d}", (int64_t)(time / 60 / 60), ((int64_t)(time / 60)) % 60, ((int64_t)time) % 60);
}
} // namespace doris