Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Is print faster than syswrite?

by ikegami (Patriarch)
on Jan 27, 2009 at 13:54 UTC ( [id://739194]=note: print w/replies, xml ) Need Help??


in reply to Is print faster than syswrite?

$| = 1; only affects STDOUT, not FILE. That accounts for the speed difference and the clobbering.

Add FILE->autoflush(1); after the open statement. (Don't forget to use use IO::Handle;) to bring print inline with syswrite.

Replies are listed 'Best First'.
Re^2: Is print faster than syswrite?
by saurabh.hirani (Beadle) on Jan 28, 2009 at 05:26 UTC
    Add FILE->autoflush(1); after the open statement. (Don't forget to use use IO::Handle;) to bring print inline with syswrite.

    Thanks. That is really useful information. I thought $| = 1 affects buffering of print function wherever it is used. I will try it out.
      $|=1; only affects the currently selected file handle, which is STDOUT by default.
Re^2: Is print faster than syswrite?
by saurabh.hirani (Beadle) on Jan 28, 2009 at 08:13 UTC

    Used FILE->autoflush(1). That stopped the clobbering and bought print to the level of syswrite. In 30 seconds both of them created a file of around 30 MB.

Re^2: Is print faster than syswrite?
by belg4mit (Prior) on Jan 29, 2009 at 05:47 UTC
    Actually, it acts on the currently select()d filehandle, which is generally STDOUT, but not always. That's why you still sometimes see the convoluted select((select(STDOUT),$|=1)[0]);

    --
    In Bob We Trust, All Others Bring Data.

      I know, I already said that. I wasn't making a general statement, I was talking about the variables in his program (STDOUT and FILE).

      And that convoluted bit? That's how autoflush does it too. (Well, a slightly safer variation.) I prefer to use autoflush cause it's way more readable.

        >I know, I already said that

        Aye. 5 minutes before I did (so please excuse the lag, it took me awhile to find the correct incantation), and in a different node :-P. The statement "$| = 1; only affects STDOUT, not FILE" doesn;t convey an understanding of this though, which was I mentioned it.

        --
        In Bob We Trust, All Others Bring Data.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-18 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found