Comment 14 for bug 868395

Revision history for this message
In , Qd-feng (qd-feng) wrote :

There is one thread in our application frequently call the localtime_r. We found the thread performance has 20% drop when change the timezone from the America/New_york to Asia/Shanghai from the system(Redhat 6,). After profile, we found it is the localtime_r cause the difference.

When set the timezone as America/New_york, the __tzfile_compute mainly call the __tzstring. While when set the timezone as the Asia/Shanghai the __tzfile_compute call the __tzset_parse_tz which consume most of the CPU time.

I also do an simple test on our HP G8 server.

  1 #include <time.h>
  2 #include <stdio.h>
  3
  4 int main(void)
  5 {
  6 struct tm newtime;
  7 time_t ltime;
  8 char buf[50];
  9
 10 for(int i=0;i<=1000000;i++)
 11 {
 12 ltime=time(&ltime);
 13
 14 localtime_r(&ltime, &newtime);
 15 }
 16 }

After compile and run command time ./a.out with the timezone as Asia/Shanghai or
America/New_York.
Asia/Shanghai
real 0m1.838s
user 0m1.628s
sys 0m0.206s

America/New_York
real 0m0.608s
user 0m0.395s
sys 0m0.211s

There is no TZ env been set on both cases. I wonder what causes the performance so difference, is it an designed behavior?

Steven