Hello,<br><br>I was wondering whether optimization can help grid-map's performance. (But I really have not done<br>much optimizing). So, I timed the following two functions which map `sin' over a really large grid:<br>
<br>(in-package :grid)<br><br>(defun optimized (arg)<br> (grid:map-grid :source arg<br> :element-function <br> #'(lambda (arg)<br> (declare<br> (optimize (speed 3) (safety 0) (debug 0))<br>
(double-float arg))<br> (the double-float (sin arg))))<br> (values))<br><br>(defun unoptimized (arg)<br> (grid:map-grid :source arg<br> :element-function <br> #'(lambda (arg) <br> (sin arg)))<br>
(values))<br><br>(progn<br> (defvar *arg* nil)<br> (setf *arg* (grid:make-grid '((foreign-array 300000) double-float)<br> :initial-element 1d0))<br> nil)<br><br>On 64bit linux & SBCL, compilation of the optimized routine generate the following notes <br>
that I don't understand:<br><br>; note: unable to avoid inline argument range check<br>; because the argument range (DOUBLE-FLOAT) was not within 2^63<br><br>; #'(LAMBDA (GRID::ARG)<br>; (DECLARE (OPTIMIZE (SPEED 3) (SAFETY 0) (DEBUG 0))<br>
; (DOUBLE-FLOAT GRID::ARG))<br>; (THE DOUBLE-FLOAT (SIN GRID::ARG)))<br>; <br>; note: doing float to pointer coercion (cost 13) to "<return value>"<br><br>Timing both routines gives very similar results:<br>
<br>GRID> (time (unoptimized *arg*))<br>Evaluation took:<br> 0.112 seconds of real time<br> 0.111983 seconds of total run time (0.110983 user, 0.001000 system)<br> [ Run times consist of 0.004 seconds GC time, and 0.108 seconds non-GC time. ]<br>
100.00% CPU<br> 335,890,827 processor cycles<br> 19,202,048 bytes consed<br><br>GRID> (time (optimized *arg*))<br>Evaluation took:<br> 0.113 seconds of real time<br> 0.112983 seconds of total run time (0.111983 user, 0.001000 system)<br>
[ Run times consist of 0.003 seconds GC time, and 0.110 seconds non-GC time. ]<br> 100.00% CPU<br> 337,194,558 processor cycles<br> 19,202,032 bytes consed<br><br>Any ideas how to properly optimize the code?<br><br>Thanks,<br>
<br>Mirko<br><br>