Path: utzoo!utgpu!cs.utexas.edu!execu!sequoia!rpp386!jfh From: jfh@rpp386.cactus.org (John F. Haugh II) Newsgroups: alt.sources.d Subject: Re: Looking for a tool to make UNIX-Time Message-ID: <18759@rpp386.cactus.org> Date: 28 Nov 90 14:45:46 GMT References: <1051@materna.uucp> <1948@necisa.ho.necisa.oz> <18748@rpp386.cactus.org> <1949@necisa.ho.necisa.oz> Reply-To: jfh@rpp386.cactus.org (John F. Haugh II) Organization: Lone Star Cafe and BBS Service Lines: 41 X-Clever-Slogan: Recycle or Die. In article <1949@necisa.ho.necisa.oz> boyd@necisa.ho.necisa.oz (Boyd Roberts) writes: >In article <18748@rpp386.cactus.org> jfh@rpp386.cactus.org (John F. Haugh II) writes: >>gack! you can compute it directly without looping. if you don't >>care about daylight savings time corrections you can get it without >>ever having to call localtime. > >Yeah, just what the guy wanted. Bugger correctness -- I mean you wouldn't >want to write code that was actually _correct_, would you now? Your algorithm makes 31 calls to localtime because it has to figure out (2 ^ 31) possible dates by binary decomposition. Let's pretend for a moment that my algorithm takes as much time as one call to localtime() to get the initial guess. Now the code gets within 1 day of the correct time, which is 86,400 seconds. It would take ceil(Log2(86,400)) = 17 calls to localtime to resolve the hard way, or ceil(Log2(24)) = 5 if you do it cleverly. Adding in the fudge factor means taking a bad guess saves you about 40%, and being cleverer saves you about 80%, or roughly 5 times as fast. >``As long as you don't care that it works'' -- a truly fine philosophy. Hey, you can always take the guess my algorithm produces and plug it into your little binary guess thingy. Of course, you don't actually need to completely figure it out, just figure if daylight savings time came or went that day. It is rumored that a major vendor once had a FORTRAN integer square root routine which was coded as (modulo syntax errors and such) INTEGER FUNCTION SQRT (N) DO 100 I = 1,65535 IF I * I .GT. N RETURN I - 1 100 CONTINUE RETURN 0 Hey - it also worked. It just took a little longer. -- John F. Haugh II UUCP: ...!cs.utexas.edu!rpp386!jfh Ma Bell: (512) 832-8832 Domain: jfh@rpp386.cactus.org "SCCS, the source motel! Programs check in and never check out!" -- Ken Thompson