Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't think buffering has much to do with it. I'm guessing it's because the terminal needs to scroll when you print a newline to it (or print enough characters to fill a line). When I benchmark these functions writing to a file or to <code>/dev/null</code>, there is not much of a difference. </p> <pre><code>use Benchmark; timethis(1000000, 'main'); timethis(1000000, 'main2'); select STDERR; $| = 0; select STDOUT; # enable buffering on STDERR sub main { print STDERR "you are the bomb. \n" } sub main2 { print STDERR "you are the bomb. " } $ perl benchmark.pl 2&gt; a_file timethis 1000000: 21 wallclock secs ( 4.67 usr + 13.38 sys = 18.05 CPU) @ 55410.87/s timethis 1000000: 21 wallclock secs ( 4.91 usr + 13.34 sys = 18.25 CPU) @ 54797.52/s $ perl benchmark.pl 2&gt; /dev/null timethis 1000000: 26 wallclock secs ( 2.86 usr + 10.36 sys = 13.22 CPU) @ 75648.69/s timethis 1000000: 27 wallclock secs ( 2.86 usr + 10.30 sys = 13.16 CPU) @ 76010.95/s $ perl benchmark.pl 2&gt; a_file (without buffering) timethis 1000000: 29 wallclock secs ( 3.78 usr + 12.14 sys = 15.92 CPU) @ 62806.18/s timethis 1000000: 29 wallclock secs ( 3.27 usr + 12.51 sys = 15.78 CPU) @ 63367.34/s $ perl benchmark.pl 2&gt; /dev/tty (window has 35 lines and buffers 10000, YMMV) [ 200000 declarations of how you are a bomb deleted ] timethis 100000: 53 wallclock secs ( 0.98 usr + 3.73 sys = 4.72 CPU) @ 21190.93/s timethis 100000: 9 wallclock secs ( 0.36 usr + 1.94 sys = 2.30 CPU) @ 43535.05/s </code></pre> <p>Summary: extra flushing reduces performance by about 10%. Extra scrolling on the terminal reduces performance by about 50%.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload