ClassicIO: Added deduction for call latency

This commit is contained in:
Karsten Jeppesen
2021-04-13 19:42:54 +02:00
parent f2187a2b7f
commit d06b416c53
8 changed files with 47024 additions and 133 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,8 @@ import java.io.IOException;
*/
public class ClassicIoUnbuffered {
private static int lineCount(String path){
private static int lineCount(String path, boolean doDance){
if ( ! doDance ) return -1;
FileInputStream fis = null;
try {
fis = new FileInputStream(path);
@@ -23,11 +24,6 @@ public class ClassicIoUnbuffered {
while ((b = fis.read()) != -1) {
if (b == '\n') cnt++;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
@@ -38,9 +34,13 @@ public class ClassicIoUnbuffered {
public static void main(String[] args){
long startTime = System.nanoTime();
System.out.println("Lines: " + String.valueOf(lineCount("input.txt")));
lineCount("", false);
long dryRun = System.nanoTime() - startTime;
startTime = System.nanoTime();
int lines = lineCount("input.txt", true);
long stopTime = System.nanoTime();
System.out.println("Time it took: " + (stopTime - startTime));
System.out.println("Lines: " + String.valueOf(lines));
System.out.println("Time it took: " + (stopTime - startTime - dryRun) + " " + dryRun);
}
}