With that little amount of text, there's no (measurable) difference between printing to STDOUT and printing to a file. It makes a huge difference if you have many, many lines to print. The reasons are:

If you print to STDOUT, you get at maximum the character processing speed of the terminal. Printing to a file, there is no such constraint.

Also, printing to STDOUT is line buffered, i.e. the output buffer is flushed after each line, which makes extra overhead. Printing to a file is block buffered, i.e. the content is flushed to the file when a data block (size as per your OS, generally a multiple of 512 Bytes) is full. So, printing to a file is generally faster.

When you close FILE the text won't get to STDOUT, it can't be printed. If you are clueful enough to use warnings or use the -w switch invoking perl, you get the warning

print() on closed filehandle FILE at line ...

<update>
Oops, I misread the post... *blush* - you are redirecting STDOUT. Well, my post may be useful anyways. - the overhead of *STDOUT = *FILE is exactly the time needed for that assignment. Now, if you do this a 1_000_000 times...
Thanks GrandFather for the hint via /msg :)
</update>

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Speed comparison between printing to STDOUT and printing to a filehandle by shmem
in thread Speed comparison between printing to STDOUT and printing to a filehandle by sberthold

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.