[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Fast SIGNUM equivalent



> 
> I have written a program that incorporates something like
> 
> 	(CASE (SIGNUM (- I1 I2))
> 	  (1 ....)
> 	  (0 ....)
> 	  (-1 ....))
> 
> where I1 and I2 are fairly small, positive integers.  This form is being
> executed a lot (hundreds of millions of times).  Is there anyway to
> speed up the test-branch part of this enough to justify whatever
> pornography is necessary?

Just use the straight-forward:

(cond ((< I1 I2) ...)
      ((= I1 I2) ...)
      ((> I1 I2) ...))

In your example you are doing a subtraction and a function call in addition to
three comparisons. Just do the three comparisons (optimized since you know
they are numbers) and save the cost of doing the subtraction and call to 
SIGNUM.

--Fred
garrett@ssv.den.mmc.com