[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fast float parsing?



I have a need to read a machine generated text file containing text
representations of floating point numbers.  I open a stream onto the
file and currently I am using the following to parse the floats:

(defun parse-float (s)
  (read s))

The problem with this is that it runs very slowly.  It allocates about
150 bytes of memory per float read (technically I guess I'm really
reading doubles).  This gets really slow because of all the garbage
collecting in reading say 1000 floats.

Does anyone have some code or hints for speeding this up?

Bonus question:  I also have to read some complex numbers in a format
like the following:

3.2e4,9.2e-3

For now I do (set-syntax-from-char #\, #\space) and then use two calls
to parse-float above.  Can I improve that?

I noted some support for SANE (particularly Str2Dec) included with beta
versions of MCL 2.0 (on the CD), that seems to have been dropped with
2.0 final.

I'm reading these floats into vectors.

Thanks,
--Steve

Stephen C. Gilardi
SQ Software
squeegee@world.std.com