El 2 de abril de 2010 19:17, 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;">
<div class="im"><br>
On Apr 2, 2010, at 11:59 AM, Álvaro Castro-Castilla wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
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>
</blockquote>
<br></div>
(floor (/ i size-y))))))))<br>
<br>
(/ i size-y) is a rational number<br>
<br>
(make-point 200 200) keeps making the same point over and over again; in C you make the point once.<br>
<br>
Try<div class="im"><br>
<br>
(declare (standard-bindings)(extended-bindings)(block)(not safe))<br>
<br></div>
(define-structure point x y)<br>
<br>
(define (fxsquare x)<br>
(fx* x x))<div class="im"><br>
<br>
(define (distance-point-point-integer a b)<br></div>
(##flonum.->fixnum (flsqrt (fixnum->flonum (fx+ (fxsquare (fx- (point-x a) (point-x b)))<br>
(fxsquare (fx- (point-y a) (point-y b))))))))<br>
<br>
<br>
(define (make-2d-field-v2 size-x size-y proc)<br>
(let ((point (make-point 0 0)))<br>
(let ((len (fx* size-x size-y)))<div class="im"><br>
(do ((vec (make-u8vector len))<br></div>
(i 0 (fx+ i 1)))<br>
((fx>= i len) vec)<br>
(point-x-set! point (fxmodulo i size-y))<br>
(point-y-set! point (fxquotient i size-y))<br>
(u8vector-set! vec i (proc point))))))<br>
<br>
(time<br>
(make-2d-field-v2<br>
500<br>
500<br>
(let ((stationary-point (make-point 200 200)))<br>
(lambda (p) (let ((d (distance-point-point-integer p stationary-point)))<br>
(if (fx> d 255) 255 d))))<br>
)<br>
)<br>
<br>
</blockquote><div><br></div><div><br></div><div>Thank you very much.</div><div><br></div><div>The clean benchmark seams to be only 30% slower in scheme compared to C. That's good enough for me. I've been also reorganizing my application code to compile those critical parts and seems to make a nice improvement. And learnt also things about optimizing scheme/gambit code.</div>
<div><br></div><div>Best regards,<br></div><div><br></div><div>Álvaro Castro-Castilla</div>