【发布时间】:2013-09-15 16:23:24
【问题描述】:
我正在调查 unix 系统上的日志记录性能。事情是我发现最昂贵的操作是获取日期。
目前我有这样的时间 -
timeb currTime;
struct tm localTime;
ftime( &currTime )
localtime_r(&currTime.time, &localTime);
我改成
struct timeval tv;
gettimeofday(&tv, NULL);
time_t curtime = tv.tv_sec;
struct tm localTime = *(localtime(&curtime));
并没有看到任何性能改进。所以我想知道这可能不是在 unix 系统上获取本地时间的最快方法吗?
请分享您对此的想法。
提前致谢。
【问题讨论】:
-
您的性能要求是什么?
-
尽其所能:)
-
我也应该能够格式化检索到的日期,如 YYYY.MM.DD HH.MM.SS.mSmS
-
不要在热线程中格式化。只需存储时间戳,然后离线格式化日志。
-
不要使用当地时间。所有内部时间都使用 UTC,并且仅转换为本地时间以向用户展示。