This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: effectiveness of gnu.math
- From: Per Bothner <per at bothner dot com>
- To: Yaroslav Kavenchuk <kavenchuk at gmail dot com>
- Cc: kawa at sourceware dot org
- Date: Fri, 25 Jan 2008 09:50:35 -0800
- Subject: Re: effectiveness of gnu.math
- References: <4799A544.9040902@gmail.com>
Yaroslav Kavenchuk wrote:
Is BigInteger slower gnu.math?
I'd like to think so, but when I tried it I got that gnu.math
was slower. gnu.math should be faster when working with small
integer (which is the common case). However, I don't understand
why gnu.math is slower for the larger numbers, since it uses
basically the same algorithm, as far as I can tell. I also don't
understand why you got different results. (However, I tried 20000
rather than 50000 presumably because I'm using a slower machine.)
I'd love to find out what is going on. Would you mind trying to
run some profiling tool (e.g. http://profiler.netbeans.org/)
to see where the <integer> version is spending its time?
I used the code at the end of this message, and compiled it with -C,
and then tried:
$ time /opt/jdk1.5/bin/java kawa.repl -e '(require <foo>)' -e '(il 20000)'
vs
$ time /opt/jdk1.5/bin/java kawa.repl -e '(require <foo>)' -e '(il
(java.math.BigInteger:valueOf 20000))'
(For some reason my code would automatically convert 20000 to a
BigInteger, so I did it manually.)
Is untyped code slower typed code very slightly?
Sometimes it can be a lot slower. However, in this case most
of the time is spent doing (I would guess) multiplications,
so that the difference made by type declaration would be minor.
(define (bil x :: <java.math.BigInteger>) :: <java.math.BigInteger>
(do (((i :: <java.math.BigInteger>) x (i:subtract
java.math.BigInteger:ONE))
((k :: <java.math.BigInteger>) java.math.BigInteger:ONE
(k:multiply i)))
; ((= i 1) k)))
((i:equals java.math.BigInteger:ONE) k)))
(define (il x :: <integer>) :: <integer>
(do (((i :: <integer>) x (- i 1))
((k :: <integer>) 1 (* k i)))
((i:equals 1) k)))
--
--Per Bothner
per@bothner.com http://per.bothner.com/