[Haskell-cafe] slow code

Ketil Malde ketil at malde.org
Wed Jun 17 03:38:56 EDT 2009

brian <briand at aracnet.com> writes:

> However, I would like to reiterate that it's the double -> string
> which is really the time/memory sink.  I verified this by printing a
> simple string based on the value (to make sure the value was
> evaluated) and it runs fast enough for me.
> Is there an efficient way to output double -> binary ?

Not as far as I know.  I had the same problem, and ended up building a
array of float representations:

  farray :: Array Int ByteString
  farray = listArray (0,9999) [B.pack (showFFloat (Just 2) i "") | i <- [0,0.01..99.99::Double]]

and using a lookup function to show the floats:

  fi :: Int -> ByteString
  fi f | f <= 9999 && f >= 0 = farray!f
       | otherwise = error ("Can't show a value of "++show f)

This works for me, since I have a very limited range of Doubles to
deal with (stored as fixed-precision Ints). 

Still, a fast and general way to output primitive data types would be
quite welcome. 

If I haven't seen further, it is by standing in the footprints of giants

More information about the Haskell-Cafe mailing list