El 2 de abril de 2010 19:17, Bradley Lucier <lucier@math.purdue.edu> escribió:
(floor (/ i size-y))))))))
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
(/ 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(define-structure point x y)
(declare (standard-bindings)(extended-bindings)(block)(not safe))
(define (fxsquare x)
(fx* x x))(##flonum.->fixnum (flsqrt (fixnum->flonum (fx+ (fxsquare (fx- (point-x a) (point-x b)))
(define (distance-point-point-integer a 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)))(i 0 (fx+ i 1)))
(do ((vec (make-u8vector len))
((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))))
)
)