[gambit-list] performance
Bradley Lucier
lucier at math.purdue.edu
Fri Apr 2 11:11:34 EDT 2010
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
More information about the Gambit-list
mailing list