mktime性能问题

#include <time.h>

int main()
{
    for (int i = 0; i < 100000; ++i)
    {
        struct tm tm = {};
        tm.tm_year = 110;
        tm.tm_mon = 1;
        tm.tm_mday = 1;
        tm.tm_hour = 0;
        tm.tm_min = 0;
        tm.tm_sec = 0;
        tm.tm_isdst = 1; // 修改这个对比一下
        mktime(&tm);
    }
}

  

tm_isdst = 1;
time ./a.out
real 0m23.143s
user 0m22.930s
sys 0m0.188s

tm_isdst = 0;
time ./a.out
real 0m0.186s
user 0m0.001s
sys 0m0.168s

tm.tm_isdst = 87324; (随即数)
time ./a.out
real 0m24.008s
user 0m23.774s
sys 0m0.213s

由此可见,tm_isdst的值对mktime的性能有很大影响。

posted @ 2014-02-19 09:46  指尖的跳动  阅读(710)  评论(0编辑  收藏  举报