Lisp HUG Maillist Archive

Optimization question

Is it possible to speed-up this code?

(defvar *global* 50)

(defun test (number iteration)
   (declare (optimize (speed 3) (safety 0) (debug 0) (space 0)))
   (declare (type (complex double-float) number))
   (or (> (the fixnum iteration) (the fixnum *global*))
       (> (the double-float (abs number)) 2.0d0)))

(defun test-times (iterations)
   (time (dotimes (x iterations) (test #c(0.5d0 0.8d0) 40))))

On LWM 5.0.1 Personal (Intel):

(time (test-times 10000000))

Timing the evaluation of (TEST-TIMES 10000000)

User time    =        9.557
System time  =        0.051
Elapsed time =       13.963
Allocation   = 800075272 bytes
0 Page faults

On SBCL on the same machine:

Evaluation took:
   0.803 seconds of real time
   0.794847 seconds of user run time
   0.0015 seconds of system run time
   0 calls to %EVAL
   0 page faults and
   0 bytes consed.

SBCL seems to be more than 10 times faster. Am I missing something? I  
double-checked that the functions are compiled.

Thanks,

Michal


Re: Optimization question

On 28/03/2007 21:19, Michal Krupka wrote:
>
> Is it possible to speed-up this code?
>
> (defvar *global* 50)
>
> (defun test (number iteration)
>   (declare (optimize (speed 3) (safety 0) (debug 0) (space 0)))
>   (declare (type (complex double-float) number))
>   (or (> (the fixnum iteration) (the fixnum *global*))
>       (> (the double-float (abs number)) 2.0d0)))
>
> (defun test-times (iterations)
>   (time (dotimes (x iterations) (test #c(0.5d0 0.8d0) 40))))
>
> On LWM 5.0.1 Personal (Intel):
>
> (time (test-times 10000000))
>
> Timing the evaluation of (TEST-TIMES 10000000)
>
> User time    =        9.557
> System time  =        0.051
> Elapsed time =       13.963
> Allocation   = 800075272 bytes
> 0 Page faults
>
> On SBCL on the same machine:
>
> Evaluation took:
>   0.803 seconds of real time
>   0.794847 seconds of user run time
>   0.0015 seconds of system run time
>   0 calls to %EVAL
>   0 page faults and
>   0 bytes consed.
>
> SBCL seems to be more than 10 times faster. Am I missing something? I 
> double-checked that the functions are compiled.
>

Erm, put the loop into the function you've optimized? At the moment the 
loop is running in whatever the default optimization level is.

__Jason


Re: Optimization question

On 28 Mar 2007, at 21:19, Michal Krupka wrote:

>
> (defun test (number iteration)
>   (declare (optimize (speed 3) (safety 0) (debug 0) (space 0)))
>   (declare (type (complex double-float) number))
>   (or (> (the fixnum iteration) (the fixnum *global*))
>       (> (the double-float (abs number)) 2.0d0)))


Other than the question of optimizing the loop, I'd be tempted to  
rebind the special variable as I suspect that access to specials is  
often not very fast.  Of course this only helps you is you can assume  
the special is a constant throughout the loop.  So you end up with  
some outer loop like:

(loop with global = *global*
       ...)


Updated at: 2020-12-10 08:46 UTC