Fastest way for line-by-line reading STDIN?

你说的曾经没有我的故事 提交于 2019-12-02 17:13:39

Looked inside BufferedReader#readLine source. There're several problems I see:

  1. It uses StringBuffer instead of StringBuilder, which creates synchronization overhead.
  2. Also there seems to be data copy overhead - not entirely sure, better check it out.
  3. Dedicated monitor object in the BufferedReader and even more synchronization overhead.

You may take your chances with two things:

  1. Writing your own buffering, which could save some time on double copying of the data.
  2. Writing your own nextLine method that would use StringBuilder and go over source data with simple cycle.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!