Hi :) I'm curious as to why flonum atrihmetic is so much slower than fixnum arithmetic. For example, the following naive benchmark runs in .8 seconds (as fast as C code!) when declare'd as fixnum, but takes 99 seconds(!) to run in flonum mode.
(define iterate-till-zero (lambda (n) (if (> n 0) (iterate-till-zero (- n 1)))))
(time (let loop ((n 1000)) (iterateTillZero 1000000) (if (> n 0) (loop (- n 1)))))
Does Gambit do some special mojo when dealing with "flonum"s? If so, is there a way to disable said mojo's? I just need fast inexact floating point arithmetic. (C style float or double numbers meet my needs just fine.)
~ TJay ~
Afficher les réponses par date
I'm assuming that in your example you are replacing the exact integer constants with floating point constants. When I try this I get a much longer execution time for the floating point version. The results of "time" indicate however that most of the time is spent in the garbage collector. This is because the (- n 1.0) in your code will compute a new flonum that is allocated in the heap. Since this is done in a tight loop with no other computation, your benchmark is really measuring the time to allocate the flonums. You can decrease the number of garbage collections, and the total execution time by increasing the heap size with the -:m option, for example
./a.out -:m10000
Marc
On 13-Nov-05, at 3:09 PM, TJay wrote:
Hi :) I'm curious as to why flonum atrihmetic is so much slower than fixnum arithmetic. For example, the following naive benchmark runs in .8 seconds (as fast as C code!) when declare'd as fixnum, but takes 99 seconds(!) to run in flonum mode.
(define iterate-till-zero (lambda (n) (if (> n 0) (iterate-till-zero (- n 1)))))
(time (let loop ((n 1000)) (iterateTillZero 1000000) (if (> n 0) (loop (- n 1)))))
Does Gambit do some special mojo when dealing with "flonum"s? If so, is there a way to disable said mojo's? I just need fast inexact floating point arithmetic. (C style float or double numbers meet my needs just fine.)
~ TJay ~ _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca http://mailman.iro.umontreal.ca/mailman/listinfo/gambit-list
Owh. Well that sure sped it up :-) So Gambit handles flonums differently from fixnum, huh? I increased the heap and got the the GC to run only 149ms out of the total 14 seconds. Fast enough for me I think, but still a far cry from fixnum performance. Just out of curiosity, is there a way to turn on native floating-point arithmetic? Assuming I'm willing to forego rationals, complex numbers, etc.
Btw Gambit is great. The C-interface is wonderful! And if syntax-case and c-lambda worked together it would be perfect! I'm lovin it ;-)
~ TJay ~