[gambit-list] performance

Bradley Lucier lucier at math.purdue.edu
Fri Apr 2 13:17:45 EDT 2010


On Apr 2, 2010, at 11:59 AM, Álvaro Castro-Castilla wrote:

>
> 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

                                          (floor (/ i size-y))))))))

(/ i size-y) is a rational number

(make-point 200 200) keeps making the same point over and over again;  
in C you make the point once.

Try

(declare (standard-bindings)(extended-bindings)(block)(not safe))

(define-structure point x y)

(define (fxsquare x)
   (fx* x x))

(define (distance-point-point-integer a b)
   (##flonum.->fixnum (flsqrt (fixnum->flonum (fx+ (fxsquare (fx-  
(point-x a) (point-x b)))
						  (fxsquare (fx- (point-y a) (point-y b))))))))


(define (make-2d-field-v2 size-x size-y proc)
   (let ((point (make-point 0 0)))
     (let ((len (fx* size-x size-y)))
       (do ((vec (make-u8vector len))
	   (i 0 (fx+ i 1)))
	  ((fx>= i len) vec)
	(point-x-set! point (fxmodulo i size-y))
	(point-y-set! point (fxquotient i size-y))
	(u8vector-set! vec i (proc point))))))

(time
  (make-2d-field-v2
   500
   500
   (let ((stationary-point (make-point 200 200)))
     (lambda (p) (let ((d (distance-point-point-integer p stationary- 
point)))
		  (if (fx> d 255) 255 d))))
   )
  )




More information about the Gambit-list mailing list