[nSLUG] Using the source -- shocking revelations about the time to get time

George N. White III gnwiii at gmail.com
Wed Aug 1 13:15:29 ADT 2007


An application I use on real unix (SGI Irix)  has been taking way to much
time to run.  I did a profile, and found that 90% of the time was in
"libc/time_comm.c", which was making lots of calls to getenv.
You can find a version of time-comm.c on the net.  In it you see:

char *p;
 if ((p = getenv("TZ")) == NULL) { return; }
 if (strcmp(p, "US/Eastern") == 0) { putenv("TZ=EST5EDT"); return; }
 if (strcmp(p, "US/Central") == 0) { putenv("TZ=CST6CDT"); return; }
 if (strcmp(p, "US/Mountain") == 0) { putenv("TZ=MST7MDT"); return; }
 if (strcmp(p, "US/Pacific") == 0) { putenv("TZ=PST8PDT"); return; }
 if (strcmp(p, "CA/Yukon") == 0) { putenv("TZ=YST9YDT"); return; }
 if (strcmp(p, "US/Hawaii") == 0) { putenv("TZ=HST10"); return; }
 return;

I suspect the current version has a much longer list.   Seeing this
suggested that the value of the TZ variable might be important, so
an experiment was in order:

$ TZ=:Canada/Atlantic time msl1info C1980181154051.L1A_MLAC

real 2046.263
user 2004.743
sys  38.789

$ TZ=AST4ADT time msl1info C1980181154051.L1A_MLAC

real 463.131
user 453.872
sys  2.638

$ TZ='GMT' time msl1info C1980181154051.L1A_MLAC
pt.info

real 200.845
user 162.594
sys  36.702

The same experiment on SunOS 5.9 shows only slight differences, but in the
same direction.  Linux (Fedora Core 6) , however, shows the reverse pattern:

$ echo "<$TZ>"
<>
[gwhite at fedcore6@MAR6030640 5.1]$ time msl1info
C1980181154051.L1A_MLAC > C1980181154051.L1A_MLAC.info

real    6m18.253s
user    1m19.588s
sys     1m34.049s
[gwhite at fedcore6@MAR6030640 5.1]$ export TZ=':Canada/Atlantic'
[gwhite at fedcore6@MAR6030640 5.1]$ date
Wed Aug  1 12:53:37 ADT 2007
[gwhite at fedcore6@MAR6030640 5.1]$ time msl1info
C1980181154051.L1A_MLAC > C1980181154051.L1A_MLAC.info

real    0m55.347s
user    0m52.140s
sys     0m2.018s

Repeating, to be sure this difference is real:

[gwhite at fedcore6@MAR6030640 5.1]$ unset TZ
[gwhite at fedcore6@MAR6030640 5.1]$ time msl1info
C1980181154051.L1A_MLAC > C1980181154051.L1A_MLAC.info

real    4m28.679s
user    1m25.673s
sys     1m27.177s

[gwhite at fedcore6@MAR6030640 5.1]$ export TZ=':Canada/Atlantic'
[gwhite at fedcore6@MAR6030640 5.1]$ time msl1info
C1980181154051.L1A_MLAC > C1980181154051.L1A_MLAC.info

real    4m37.870s
user    0m52.886s
sys     0m2.051s

[don't pay attention to the "real" time, as this is running in a VM
and mcaffee started
running on the host]

I found another instance where the time spent in time calculations matters:

<http://www.openmalaysiablog.com/2007/06/will-readabil-1.html>

A benchmark program is included if anyone else is interested.



-- 
George N. White III <aa056 at chebucto.ns.ca>
Head of St. Margarets Bay, Nova Scotia



More information about the nSLUG mailing list