This post highlights the issue with overly zealous mods on SO who marked the question as off topic. Nothing about this is off topic, and it turned out to be very interesting answer.
Entirely unrelated, but this headline made me notice that Chrome finally supports entering " in the find-in-page box and having it match so-called smart quotes.
Oh good lord. This question is more about properly isolating your tests (i.e. writing the characters to /dev/null and getting rid of the "random" call) and properly profiling code (which would show high CPU consumption on the <i>console</i>, not the program writing to stdout) more than anything "tricky" about performance.
Hilarious! I never see confirmation bias in action so much as when SO answers get posted on HN:<p>"See, this is exactly what's wrong with SO."<p>"Really? Because it seems like a perfect example of why SO works perfectly."<p>Of course, I find I am increasingly disposed to read the comments that way...
This, incidentally, is a good user interface study. The terminal emulator works so well that most users don't even know it's there. But it's actually a pretty complex piece of software.
Apparently the answer had to do with terminal word-wrapping. A good test would be to write the output to a file instead of the terminal and compare the difference in timing.
There are terminals that do word wrapping?<p>Well, I shouldn't be surprised... There are people who try to code with a proportional font too, so I guess anything is possible, though it may not make sense to me.
I'm actually a little surprised that the answer wasn't something along the lines of "# is simple straight lines, while B requires a bunch of Bezier splines for TrueType to render." I guess the graphics cards must accelerate that or something. I'm surprised that line-breaking algorithms take that long.
1) Asking about running times on code with calls to an RNG ... remove the randomness first, profile repeatedly<p>2) Outputting to STDOUT can have some serious overhead depending on where you're actually rendering the text-- textview inside your IDE? Crazy, off-the-wall terminals? Let's dump this to a file and see how long it takes