[RFC] Faster implementation of Integer to string conversion.
Simon Marlow
simonmarhaskell at gmail.com
Fri Apr 28 05:29:15 EDT 2006
Bertram Felgenhauer wrote:
> several people have noted that printing integers is slow. The attached
> patch implements a faster version of the jtos (read: positive integer
> to string) function in GHC's Num library. The algorithm is a divide and
> conquer algorithm, that converts numbers to base b by converting them
> to base b^2 first, and then splitting the digits.
>
> Notes:
> - I've tested the speed on my computer (which has an Athlon XP processor)
> and it seems to be of comparable speed as the original for small numbers
> and way faster for big numbers (read: a few hundred or thousand digits).
> - The changed conversion code is a much better list producer than the
> original one, which generates digits starting with the last.
> - There's similar code in Numeric.lhs, that deals with arbitrary bases.
> The current patch does not deal with this. (see questions below)
> - musabi on #haskell mentioned that there's interest in replacing GMP as
> the bignum implementation. This is independent of changing this string
> conversion, as far as I can see.
I'm tempted to commit this patch, but I want to make sure it's not a
performance regression for small integers. When you say "comparable"
performance, what does that mean exactly? Printing small integers is by
far the most common case. Perhaps we should special-case the small
integers (i.e. the S# constructor)?
Cheers,
Simon
More information about the Libraries
mailing list