CyberPeasant wrote:

> > while (ch!='\n') { ch=fgetc(F); ++x; line[x]=ch;}  //Is Getc Any Faster
> > Than FRead???
> 
> Marginally.  Getc and fgetc aren't the same, you know. For char-at-a-time
> input, getc will be slightly faster than fgetc, since getc is a macro. 
> Both will probably beat fread in this context.

Note that on glibc-2 (libc-6), the fastest way to read a single
character is to use getc_unlocked(). This is #define'd to
_IO_getc_unlocked, which is defined as

#define _IO_getc_unlocked(_fp) \
       ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow(_fp) \
        : *(unsigned char*)(_fp)->_IO_read_ptr++)

i.e. it just reads a byte from the buffer (after checking for
underflow).

getc() is a function, which does a bit more work, as it needs to lock
the buffer (getc() is thread-safe, getc_unlocked() isn't).

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to