On Sat, 19 Sep 2009, Alexander Burger wrote:
to my surprise my Pico Lisp version was much slower than my Scala version.
You've hit upon an old problem. Conversion from internal to decimal
representation in PicoLisp takes too long. We had a similar discussion
here some time ago, initiated by Tomas Hlavaty.
You can see this easily if you look at the steps separately (I put a 'T'
at the end of each line to avoid the actual output of the big numbers):
: (bench (** Big 300)) T
This is very short in comparison to decimal formatting:
: (bench (format (** Big 300))) T
Oh my, oh my...
/me slaps himself
I forgot the return value... =/
Yeah, the problem is not the bignum implementation, but the bignum ->
BTW, you can also directly 'chop' a number, without the need of
'format'ing it. But this won't change anything either:
: (bench (chop (** Big 300))) T
Same goes for direct printing:
: (bench (out "/dev/null" (println (** Big 300)))) T
In all these cases, the final conversion took about 360 times longer
than the actual calculation.
Could I have written the Pico Lisp code differently to make it faster?
Not the Lisp code, the conversion goes completely in the kernel. But I
have also no better idea how to do a decimal conversion faster.