Probably nanoseconds, so no big deal

I thought that sounded optimistically fast, so here's the benchmark:

$ cat pore.pl #!/usr/bin/env perl use strict; use warnings; use Benchmark 'cmpthese'; open my $fh, '>', '/tmp/wp.txt' or die $!; cmpthese (10000, { 'print' => sub { print $fh "x\n"; }, 'echo' => sub { system "echo x >> /tmp/we.txt"; } } ); close $fh; exit; $ perl pore.pl (warning: too few iterations for a reliable count) Rate echo print echo 317/s -- -100% print 10000000000000000000/s 3153000000000000000% --

Yes, print is so much faster than shelling out each time it is practially immeasurable. They'll get closer if you do the open and close inside the sub of course and that would mean losing the buffering too but it's still going to beat the pants off a fork and a shell invocation each time just to do a one-line write.

Upshot: on my machine here it isn't nanoseconds - it's more like 3 milliseconds.


In reply to Re^4: snmpget is missing some values by hippo
in thread snmpget is missing some values by leostereo

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.