in reply to how many chars/bytes does STDOUT buffer

$ perl -MTime::HiRes=sleep -e'while(1){print ".";sleep 0.001}' | perl + -le'print sysread(STDIN,$rec,1024*1024)' 4096

(no, the sleep isn't strictly necessary, but it makes the buffering effect more obvious.)

- tye        

Replies are listed 'Best First'.
Re^2: how many chars/bytes does STDOUT buffer (test)
by choroba (Cardinal) on Apr 02, 2015 at 13:38 UTC
    I'm getting 8192. Perl 5.14.4 on Cygwin 64.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Perl's IO buffer size was changed from 4096 pre-5.14 to 8192 post 5.14. It's also configurable at build time.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
      In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

      Yeah, the point was the test, not the sample number produced. Since "line-buffer STDOUT to a terminal but full-buffered to a file or pipe" is the pattern for almost all programs, not just Perl, it is likely that the buffering is not done by Perl and so the size depends on your OS and/or C library version. Though, Perl has several choices of I/O layer implementation and one or more of them might re-implement that standard I/O buffer behavior but might choose different default sizes (though, I recall there being ways to specify buffering and the standard http://perl.plover.com/FAQs/Buffering.html documents such and much more).

      - tye        

        "line-buffer STDOUT to a terminal but full-buffered to a file or pipe" is the pattern for almost all programs, not just Perl"

        can you elaborate on this . i didn't understand it fully.