[Haskell-cafe] Reading integers
bertram.felgenhauer at googlemail.com
Wed Sep 6 18:12:47 EDT 2006
Neil Mitchell wrote:
> >Currently I have a single module that provides reading operations
> >for Integers and Ints. I'm not quite sure what to do with it.
> Get it into base! Where it is, or what its called is less relevant -
Ok, one vote for base.
> >I'm pondering breaking compatibility with Haskell 98 to some extent
> >and implementing read instances for Int and Integer that don't diverge
> >on weird inputs, but handle all valid numbers that Haskell 98 supports.
> Thats nice, but a stand alone readInt that is not tied to reads, and
> the whole "leftover parse" thing can be dropped - probably for better
Performance won't be much better I think. A first attempt at this was
actually slower (I have not yet investigated why), and the functions are
more useful with leftover parsing, in my opinion (in the MUL problem it
saved a call to words - which bought a little bit of extra performance).
> Of course, making an existing read faster is also good.
I think it's very desirable because that's what people use most often.
> Any chance of a very quick summary of the results? i.e. on average x%
> faster, but y% faster for integers over size z? Saves everyone darcs's
> in. As far as I am concerned, the code is a black box, but the
> statistics are something everyone will want.
For small integers (absolute value less than 1000), Numeric.readDec
is 5 to 10 times faster than reads and my readInteger is 5 to 8
times faster than readDec.
For medium integers (about 100 digits), readDec and reads are about
the same speed while readInteger is about 10 times faster.
For larger integers the speedup becomes larger, too. At 100k digits,
it reaches 100 (timed using ghci - but hopefully the number is correct
All measurements were done with ghc 6.5, compiling with -O.
More information about the Haskell-Cafe