in reply to Fast file reader

Wouldn't it be easier to call setvbuf for a file handle and rely on stdio for the performance boost?
AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.

Replies are listed 'Best First'.
(tye)Re: Fast file reader
by tye (Sage) on Mar 16, 2001 at 01:07 UTC

    Actually, on "non broken" platforms, Perl's I/O is more efficient than stdio.h I/O because it knows how to peak inside stdio's internal structures to avoid extra copying of data.

    Unfortunately, Linux is a "broken" platform in this regard so Perl's native readline (<>) is 4-times slower than it should be.

    I suspect benchmarking this code will show that it is slower than plain <IN> when run on many old-style Unix platforms but faster than <IN> on Linux.

    I'd like to encourage effort toward "fixing" Perl's I/O optimizations for Linux and other platforms (written in C).

            - tye (but my friends call me "Tye")
      Thanks tye.
      I'd been wondering for a while why a read kludge like this would be faster than Perl for IO.
      Saves me asking the question in another post. :)
      I'll be keeping my eyes open for the fix if/when it appears, as a huge amount of my current work involves Perl and file IO.

      Malk
        You may want to use sysread() to spped up file I/O. Huameng