This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Speeding up floating point number reading
- From: Daniel Kraft <d at domob dot eu>
- To: Fortran List <fortran at gcc dot gnu dot org>
- Date: Mon, 29 Dec 2008 16:58:57 +0100
- Subject: Re: Speeding up floating point number reading
- References: <4958F028.4030304@domob.eu>
Sorry guys,
but with the obvious fix for the return value, the program really works
(even with the checks enabled)...
Daniel
as promised on PR 38654, I gave floating point reading a look. I used
the attached program for testing with -O3 -static. It takes around 31s
on my system with an unpatched gfortran 4.4.
First, I tried to replace the strtod call in
libgfortran/io/read.c:convert_real with a custom made parser according
to the one I implemented for FreeWRL, and even got execution time to
around 29s (a bit surprising, I though strtod must be well optimized).
However, I then looked further, and discovered that read_f, the caller
of convert_real, is already doing most of the work! And then, it prints
the number back to a string just to parse it again using convert_real...
With the simple (experimental and rough) patch attached, the final
floating point value can be calculated with little additional effort in
read_f, without ever calling convert_real. This cuts the execution time
in half to 15.5s!
The only weak point is that I'm not sure if we may experience rounding
errors in parsing the float due to all the *10 and + operations, and
that could be something strtod takes care of. On the other hand, I
think this is rather unlikely. What do you think about this one?
I'm going to work out a real patch, that handles all kinds, not just
double, and in addition cleans up all now-useless stuff. Comments welcome!
Yours,
Daniel
--
Done: Arc-Bar-Cav-Rog-Sam-Tou-Val-Wiz
To go: Hea-Kni-Mon-Pri-Ran