<p>谢谢你的评论!我最终在你的帮助下自己回答了。不过,回答你自己的问题让人觉得很肮脏。</p>
<p><strong>问题1:为什么打印到标准输出速度慢?</strong></p>
<p><strong>回答:</strong>打印到stdout是<em>而不是</em>固有的速度慢。你工作的终端是慢的。它与应用程序端的I/O缓冲(例如:python文件缓冲)几乎没有关系。见下文。</p>
<p><strong>问题2:能否加快速度?</strong></p>
<p><strong>回答:</strong>可以,但似乎不是从程序方面(从“打印”到标准输出的方面)。要加快速度,请使用速度更快的不同终端仿真器。</p>
<p>解释。。。</p>
<p>我尝试了一个自称“轻量级”的终端程序,名为<code>wterm</code>,得到了显著的<em>效果。下面是我的测试脚本(在问题的底部)在1920x1200英寸的同一个系统上运行时的输出,在该系统中,使用gnome终端的基本打印选项花费了12秒:</p>
<pre>
-----
timing summary (100k lines each)
-----
print : 0.261 s
write to file (+fsync) : 0.110 s
print with stdout = /dev/null : 0.050 s
</pre>
<p>0.26秒比12秒好多了!我不知道<code>wterm</code>是否更聪明,它是如何呈现屏幕,按照我的建议(以合理的帧速率呈现“可见”尾部),还是它只是“做得比<code>gnome-terminal</code>少”。不过,就我的问题而言,我得到了答案。<code>gnome-terminal</code>是慢的。</p>
<p>所以-如果你有一个长时间运行的脚本,你觉得它是缓慢的,它喷出大量的文本到标准输出。。。换个终端试试看有没有更好的!</p>
<p>注意,我从ubuntu/debian存储库中随机抽取了<code>wterm</code>。<a href="http://sourceforge.net/projects/wterm/" rel="noreferrer">This link</a>可能是同一个终端,但我不确定。我没有测试任何其他终端仿真器。</p>
<hr/>
<p>更新:因为我不得不抓痒,我用相同的脚本和全屏(1920x1200)测试了一整堆其他终端模拟器。我手动收集的数据如下:</p>
<pre>
wterm 0.3s
aterm 0.3s
rxvt 0.3s
mrxvt 0.4s
konsole 0.6s
yakuake 0.7s
lxterminal 7s
xterm 9s
gnome-terminal 12s
xfce4-terminal 12s
vala-terminal 18s
xvt 48s
</pre>
<p>记录的时间是手动收集的,但它们非常一致。我记录了最好的值。很明显是YMMV。</p>
<p>作为奖励,这是一个有趣的旅行,一些不同的终端仿真器提供了那里!我很惊讶我的第一次“替补”考试竟然是最好的。</p>