Fastest way for line-by-line reading STDIN?

前端 未结 1 635
滥情空心
滥情空心 2021-01-31 10:26

I\'m looking for the most time-efficient way to read STDIN line-by-line.

The first line is the number of conditions to test. All the following lines are conditions (stri

相关标签:
1条回答
  • 2021-01-31 11:09

    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.
    0 讨论(0)
提交回复
热议问题