[gambit-list] performance

Ralf Schmitt ralf at brainbot.com
Sat Apr 3 05:43:57 EDT 2010


Bradley Lucier <lucier at math.purdue.edu> writes:

> This function in C
>
> int distance_point_point(struct point *p1, struct point *p2) {
> 	return sqrt( pow( p1->x - p2->x, 2) + pow( p1->y - p2->y, 2) );
> }
>
> is translated quite literally into (Gambit) scheme as
>
> (define (distance-point-point a b)
>    (##flonum.->fixnum (flsqrt (fl+ (flexpt (fixnum->flonum (point-x  
> a)) 2.)
> 				  (flexpt (fixnum->flonum (point-y a)) 2.)))))
>
> 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.
>
> 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.
>
> So these codes are in only a rough sense "equivalent".
>
> If you add the declarations
>
> (declare (standard-bindings)(extended-bindings)(block)(not safe))
>
> then things should go a bit faster.
>
> Brad
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list



More information about the Gambit-list mailing list