是否值得保留本地副本struct tm
並僅在需要時進行更新;下面FUNC不是線程安全的......還我見過的CPU時間只有6至7%,可節省...緩存localtime_r()是否值得?
struct tm* custom_localtime (time_t now_sec)
{
static time_t cache_sec;
static struct tm tms;
if (now_sec != cache_sec) {
cache_sec = now_sec;
localtime_r(&cache_sec, &(tms));
}
return(&tms);
}
其他細節: - 我的應用程序,使得超過3000 /秒的來電localtime_r()
發現了至少33%的CPU節省時間,當我緩存格式"2011-12-09 10:32:45"
的時間戳字符串againttime_t
秒
謝謝大家NOS,asc99c和米爾恰。
什麼是你的價值標準? – Jon
節省時間在我撥打localtime_r()時寫入日誌等的時間超過3000 /秒的情況下... – SparKot
如果您將時間保存在您的事宜上,那麼請執行此操作。如果沒關係,不要這樣做。我們如何才能確定差異是否與你有關? – Jon