[gambit-list] Why is flonum arithmetic so slow?

Marc Feeley feeley at iro.umontreal.ca
Sun Nov 13 21:07:24 EST 2005


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 at iro.umontreal.ca
> http://mailman.iro.umontreal.ca/mailman/listinfo/gambit-list




More information about the Gambit-list mailing list