last year we had this discussion:
On Thu, Apr 02, 2009 at 09:20:57AM +0100, Tomas Hlavaty wrote:
> Hi Alex,
> > However, I am aware of the fact that in picoLisp the printing of
> > numeric results is often much more expensive than the actual
> > calculations, due to the conversions necessary for the decimal base.
> > If I take out the final (prinl Y) from gmp-test2.l, I get:
> > It makes a considerable difference.
> Interesting, it does not seem to make much difference with the C
> version when I take the final 'printf' out of the C code.
Now, while playing with the task "Arbitrary-precision integers" at
(** 5 (** 4 (** 3 2)))
I hit upon that problem again. While the actual calculation takes only a
fraction of a second (the '->' prompt appears), formatting the decimal
output (183231 digits) takes 634 seconds on the 64-bit version.
Again, this bothered me, and I investigated a little deeper. The
bottleneck is the binary-to-decimal conversion. PicoLisp uses for that
an algorithm with binary code digits. It consists of a nested loop,
where the innter loop manipulates BCD-bytes with shifts and additions
It occurred to me that this could be sped up considerably with using
larger "digits". So I rewrote it, so that a single BCD digit is no
longer a byte, but a complete word, holding 9 BCD digits on 32 bits, and
18 digits on 64 bits.
This helped a lot! The 634 seconds reduced to 37 seconds, a 17-fold
speed improvement :-)