<p>I was reading about output buffering in JavaScript <strong><a href="http://www.webreference.com/programming/javascript/jkm3/4.html" rel="nofollow noreferrer">here</a>,</strong> and was trying to get my head around the script the author says was the fastest at printing 1 to 1,000,000 to a web page. (Scroll down to the header "The winning one million number script".) After studying it a bit, I have a few questions: </p>

<ul>
<li>What makes this script so efficient compared to other approaches? </li>
<li>Why does buffering speed things up? </li>
<li>How do you determine the proper buffer size to use?</li>
<li>Does anyone here have any tricks up her/his sleeve that could optimize this script further?</li>
</ul>

<p>(I realize this is probably CS101, but I'm one of those blasted, self-taught hackers and I was hoping to benefit from the wisdom of the collective on this one. Thanks!)</p>

I would bet the slowest thing in printing 1m numbers is the browser redrawing the page, so the fewer times you call document.write(), the better.  Of course this needs to be balanced against large string concatenations (because they involve allocating and copying).
Determining the right buffer size is found through experimentation.
In other examples, buffering helps align along natural boundaries. Here are some examples
32 bit CPUs can transfer 32 bits more efficiently.
TCP/IP packets have maximum sizes.
File I/O classes have internal buffers.
Images, like TIFFs, may be stored with their data in strips.
Aligning with the natural boundaries of other systems can often have performance benefits.