Java:System.out.println()背后的原因是什么? [英] Java: What's the reason behind System.out.println() being that slow?

查看:238
本文介绍了Java:System.out.println()背后的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于可以在文本编辑器中完成的小型逻辑程序,为了跟踪,我使用经典的 System.out.println()

For small logical programs that can be done in a text editor, for tracing I use the classic System.out.println().

我想大家都知道在大量迭代的块中使用它是多么令人沮丧。为什么这么慢?这是什么原因?

I guess you all know how frustrating it is to use that in a block of high number of iterations. Why is it so slow? What's the reason behind it?

推荐答案

这与JVM无关。将文本打印到屏幕仅涉及用于绘制字母并且特别是滚动的OS的大量工作。如果你将System.out重定向到一个文件,它会更快。

This has nothing whatsoever to do with the JVM. Printing text to screen simply involves a lot of work for the OS in drawing the letters and especially scrolling. If you redirect System.out to a file, it will be much faster.

这篇关于Java:System.out.println()背后的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆