title: Fastest way for line-by-line reading STDIN?
body: <p>I'm looking for the most time-efficient way to read STDIN line-by-line.</p>
  
  <p>The first line is the number of conditions to test.
  All the following lines are conditions (strings) with a maximum of 100 000 characters.</p>
  
  <p>I have already tried the following (plus result for 4 times 90 000 characters:</p>
  
  <ul>
  <li><p>Scanner with a while-loop (7255 ms)</p>
  
  <pre><code>Scanner sc = new Scanner(System.in);
  int numberOfLines = Integer.parseInt(sc.nextLine());
  long start = 0;
  int i = 1;
  while (i&lt;=numberOfLines){
      start = System.currentTimeMillis();
      sc.nextLine();
      Debug.println((System.currentTimeMillis()-start) + "ms for scanner while");
      i++;
  }
  </code></pre>
  
  <ul>
  <li>Results :
  <ol>
  <li>3228ms for scanner while</li>
  <li>2264ms for scanner while</li>
  <li>1309ms for scanner while</li>
  <li>454ms for scanner while</li>
  </ol></li>
  </ul></li>
  <li><p>Scanner with a for-loop (7078 ms)</p>
  
  <pre><code>Scanner sc = new Scanner(System.in);
  int numberOfLines = Integer.parseInt(sc.nextLine());
  long start = 0;
  for (int i = 1; i&lt;= numberOfLines;i++){
      start = System.currentTimeMillis();
      sc.nextLine();
      Debug.println((System.currentTimeMillis()-start) + "ms for scanner for");
      //i++;     
  }
  </code></pre>
  
  <ul>
  <li>Results :
  <ol>
  <li>3168ms for scanner for</li>
  <li>2207ms for scanner for</li>
  <li>1236ms for scanner for</li>
  <li>467ms for scanner for</li>
  </ol></li>
  </ul></li>
  <li><p>BufferedReader with a for-loop (7403 ms)</p>
  
  <pre><code>try {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  
  int numberOfLines = Integer.parseInt(br.readLine());
  long start = 0;
  for (int i = 0; i&lt; numberOfLines;i++){
      start = System.currentTimeMillis();
      br.readLine();
      Debug.println((System.currentTimeMillis()-start) + "ms for bufferreader for");
      //i++;
  }
   } catch (Exception e) {
  System.err.println("Error:" + e.getMessage());
  </code></pre>
  
  <p>}</p>
  
  <ul>
  <li>Results :
  <ol>
  <li>3273ms for bufferreader for</li>
  <li>2330ms for bufferreader for</li>
  <li>1293ms for bufferreader for</li>
  <li>507ms for bufferreader for</li>
  </ol></li>
  </ul></li>
  <li><p>BufferedReader with a while-loop (7461 ms)</p>
  
  <pre><code>try {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  
  int numberOfLines = Integer.parseInt(br.readLine());
  int i=0;
  long start = 0;
  while(i&lt; numberOfLines){
      start = System.currentTimeMillis();
      br.readLine();
      Debug.println((System.currentTimeMillis()-start) + "ms for bufferreader while");
      i++;
  }
   } catch (Exception e) {
  System.err.println("Error:" + e.getMessage());
  </code></pre>
  
  <p>}</p>
  
  <ul>
  <li>Results :
  <ol>
  <li>3296ms for bufferreader while</li>
  <li>2358ms for bufferreader while</li>
  <li>1307ms for bufferreader while</li>
  <li>500ms for bufferreader while</li>
  </ol></li>
  </ul></li>
  </ul>
  
  <p>While debugging the time taken, i noticed that the time-taken decreases after each read.
  Is it possible to restrict the bytes that are initialized (f.e. : If you have a maximum of 100.000 chars, limit the scanner/bufferedreader to only initialize 100 000 chars. After a read it will need to refill itself with the next 100 000 chars)</p>
  
  <p>Any ideas on this matter are more than welcome.</p>
  
  <p>EDIT : Added the code for each scenario along with the time-taken per line read. Also changed 100.000 to 100 000 to read more easily.</p>