Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Time::HiRes strange behavior

by rubasov (Friar)
on Feb 06, 2010 at 15:26 UTC ( #821751=note: print w/ replies, xml ) Need Help??


in reply to Re: Time::HiRes strange behavior
in thread Time::HiRes strange behavior

One more thought on this thread:

It's all down to the buffering done by the pipe.
As far as I know how pipes work this is not entirely correct.

Consider a stripped down version of your pipeline:

perl -MTime::HiRes=gettimeofday -e '$|++; print gettimeofday() . "\n" +while sleep 1' |\ perl -MTime::HiRes=gettimeofday -e '$|++; print gettimeofday() . " " . + $_ while <>'

Using this stripped pipeline you won't see any serious buffering related delay. Here's the why: If the process at the write end writes any amount (less then the pipe buffer) to the pipe, then the process at the read end will be able to read it irrespectively the state of the pipe buffer. If you omit the commands with possibly buffered output in your pipeline, you won't get the buffer filling delay. I think the result you showed us is caused by your version of tee (or less likely tail), by using buffered output. (I cannot see the same results with the current GNU versions of tee and tail.)

Of course the pipe buffer can cause delays: if the buffer is empty then the reads will block, if the buffer is full then the writes will block. But reads will not block just because the buffer is not full.

So in my comprehension your delayed results are all down to output buffering but not to pipe buffering.


Comment on Re^2: Time::HiRes strange behavior
Download Code
Re^3: Time::HiRes strange behavior
by BrowserUk (Pope) on Feb 06, 2010 at 15:40 UTC

    Indeed! You are correct. And it does seem to be tee that's doing the buffering.


    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".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://821751]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-08-23 18:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (178 votes), past polls