Re: Binary v. Text, why is it faster?



Arctic Fidelity wrote:
I have constantly seen and heard that reading binary data is faster than reading textual data. I have always presumed this to be a fact. But now I am at the point where I would like to understand why.

I was trying to think about it, and it has rather confused me. To my understanding, reading a text file is reading in the bytes which correspond to, for example, ASCII character codes. But if we are dealing with a 1-byte character encoding, how is it slower to read in 'a' rather than some binary representation of that?

And in addition to this, what is the actual difference between binary and textual files? I had always thought that a binary file was simply a file composed of any combination of bytes, whereas a text file was a file composed of a limited subset of the bytes available to a binary file. Am I misunderstanding something here?

I guess I just don't see how reading in AF would be slower just because AF appears in a text file instead of a "binary" file?

- Arctic

A point others haven't made yet is also that text files are often human-readable, so there can be additional stuff in there that has to be processed (and usually ignored), so for instance a binary representation of the numbers 1-5 might just contain five bytes 01 02 03 04 05, but a text version of the same data might read something like:

[object1]
numvalues=5
value1=1
value2=2
value3=3
value4=4
value5=5

The other difference between binary and text files is that end of line characters are significant in the latter. In a binary file an 0x0a is just an 0x0a, but on some operating systems this must be accompanied by an 0x0d. This is why it's important to ftp files in the correct mode, particularly if downloading, for instance, a text file created on Unix to a Windows box. If you download a binary file in text mode any 0x0a found will have an 0x0d added to it, thus corrupting the file.

Also some editors will helpfully display an unaccompanied 0x0a as ^M which is really helpful, thanks guys, really makes things a lot more readable, as if you didn't understand what had happened here.

Dave.
.



Relevant Pages

  • Re: Binary v. Text, why is it faster?
    ... than reading textual data. ... To my understanding, reading a text file is reading in the bytes which correspond to, for example, ASCII character codes. ... Software capable of understanding the particular binary format method of encoding information must be used to interpret the information in a binary formatted file. ...
    (comp.programming)
  • Re: Binary v. Text, why is it faster?
    ... reading textual data. ... But watch what happens when I concatenate two copies together: ... EOF character per file and it better be the last one. ...
    (comp.programming)
  • Re: Binary v. Text, why is it faster?
    ... reading textual data. ... They are the same because often a text file IS a binary file. ... file is nothing more than a binary file with only ASCII characters. ...
    (comp.programming)
  • Binary v. Text, why is it faster?
    ... I have constantly seen and heard that reading binary data is faster than reading textual data. ... I guess I just don't see how reading in AF would be slower just because AF appears in a text file instead of a "binary" file? ...
    (comp.programming)
  • Re: asymptote/hyperbola?
    ... He's presenting a character who's talking math. ... So a responsible reading will account for this nonsense in at least one ... Translation is the foundation of every reading. ... >> On your last hermeneutic occasion, you informed us that all the dancer ...
    (rec.arts.books)