Re: parsing a file..




"broli" <Broli00@xxxxxxxxx> wrote in message
news:44a0de39-63ca-475d-abac-85933594205d@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Mar 14, 2:18 pm, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:
broli said:

I need to parse a file which has about 2000 lines and I'm getting
told that reading the file in ascii would be a slower way to do it and
so i need to resort to binary by reading it in large chunks. Can any
one please explain what is all this about ?

Someone's pulling your leg. 2000 lines of text is nothing. Just write the
program so that it's clear, correct, and easy to understand. Then, if and
only if it's too slow (and you should define the "fast enough"/"too slow"
boundary before you start writing the program), it's time to think about
how it might be made faster.

Well the data that I'm trying to read is sceintific data( dobule
precision) and i had written a program a while ago which read all the
data and stored it perfectly in data structures. There were no hassles
as I simply used the f- functions specifications by C std. But then I
was told that " normally we don't read scientific data in ascii for
accuracy and speed concerns" which made me wonder what was so wrong ?
I could parse 2000 lines in hardly any time and there was no problem
with ascii either.

These other people are right. But they weren't necessarily talking about
your 2000-line file (assuming the lines are reasonable length).

In general, reading very large text files full of floating point numbers, or
smaller files many times, will be slower because of needing to parse and
recalculate each number.

But if this code will only ever be used to read that particular size file,
and is fast enough, then forget it.

There's also a matter of accuracy: a textual representation will be a little
different from the binary, but if your input is already in text form, then
you can't do much about it.

--
Bart


.



Relevant Pages

  • Re: parsing a file..
    ... told that reading the file in ascii would be a slower way to do it and ... so i need to resort to binary by reading it in large chunks. ...
    (comp.lang.c)
  • Re: parsing a file..
    ... told that reading the file in ascii would be a slower way to do it and ... so i need to resort to binary by reading it in large chunks. ... It will be slower in the great majority of cases. ... sys 0m0.001s ...
    (comp.lang.c)
  • Re: parsing a file..
    ... told that reading the file in ascii would be a slower way to do it and ... so i need to resort to binary by reading it in large chunks. ... It will be slower in the great majority of cases. ... The data file is probably ...
    (comp.lang.c)
  • Re: parsing a file..
    ... told that reading the file in ascii would be a slower way to do it and ... so i need to resort to binary by reading it in large chunks. ... It will be slower in the great majority of cases. ...
    (comp.lang.c)
  • parsing a file..
    ... I need to parse a file which has about 2000 lines and I'm getting ... told that reading the file in ascii would be a slower way to do it and ... so i need to resort to binary by reading it in large chunks. ...
    (comp.lang.c)