El 2 de abril de 2010 17:11, Bradley Lucier <span dir="ltr"><<a href="mailto:lucier@math.purdue.edu">lucier@math.purdue.edu</a>></span> escribió:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

This function in C<br>
<br>
int distance_point_point(struct point *p1, struct point *p2) {<br>
        return sqrt( pow( p1->x - p2->x, 2) + pow( p1->y - p2->y, 2) );<br>
}<br>
<br>
is translated quite literally into (Gambit) scheme as<br>
<br>
(define (distance-point-point a b)<br>
  (##flonum.->fixnum (flsqrt (fl+ (flexpt (fixnum->flonum (point-x a)) 2.)<br>
                                  (flexpt (fixnum->flonum (point-y a)) 2.)))))<br>
<br>
The C type inference rules, the automatic conversion of int to double and back, and the header <math.h> takes care of all of that.<br>
<br>
And you're allocating manipulating lists in the Scheme version, but using an array in the C version, which you could also do in the scheme version.<br>
<br>
So these codes are in only a rough sense "equivalent".<br>
<br>
If you add the declarations<br>
<br> (declare (standard-bindings)(extended-bindings)(block)(not safe))<br>
<br>
then things should go a bit faster.<br>
<br>
Brad<br></blockquote><div><br></div><div>Actually, I tried that code, and this runs faster:</div><div><br></div><div>(define (distance-point-point-integer a b)<br>  (integer-sqrt (fx+ (expt (- (point-x a) (point-x b)) 2)<br>

                           (expt (- (point-y a) (point-y b)) 2))))</div><div><br></div><div>What does actually help (~2x) is the declaration: (declare (standard-bindings)(extended-bindings)(block)(not safe))</div><div><br>

</div><div>Now I have it down to ~350ms. which is 10-20x the C version. with floating point. I can't understand how the straightforward u8vector version (the second in the scheme code) is slower (~500ms) than the same thing with consed lists and afterwards transformed to a u8vector :S<br>

<br></div><div><br></div><div>Best regards</div><br>