Looking for a tool to make UNIX-Time

John F. Haugh II jfh at rpp386.cactus.org
Thu Nov 29 01:45:46 AEST 1990


In article <1949 at necisa.ho.necisa.oz> boyd at necisa.ho.necisa.oz (Boyd Roberts) writes:
>In article <18748 at rpp386.cactus.org> jfh at 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 at rpp386.cactus.org
"SCCS, the source motel!  Programs check in and never check out!"
		-- Ken Thompson



More information about the Alt.sources.d mailing list