ClassicIO: Added deduction for call latency
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,8 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class ClassicIoBuffered {
|
public class ClassicIoBuffered {
|
||||||
|
|
||||||
public static int lineCount(String path){
|
private static int lineCount(String path, boolean doDance){
|
||||||
|
if ( ! doDance ) return -1;
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
try {
|
try {
|
||||||
fis = new FileInputStream(path);
|
fis = new FileInputStream(path);
|
||||||
@@ -41,9 +42,13 @@ public class ClassicIoBuffered {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
long startTime = System.nanoTime();
|
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();
|
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) + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class ClassicIoManBuffered {
|
public class ClassicIoManBuffered {
|
||||||
|
|
||||||
public static int lineCount(String path){
|
private static int lineCount(String path, boolean doDance){
|
||||||
|
if ( ! doDance ) return -1;
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
try {
|
try {
|
||||||
fis = new FileInputStream( path );
|
fis = new FileInputStream( path );
|
||||||
@@ -36,9 +37,13 @@ public class ClassicIoManBuffered {
|
|||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
long startTime = System.nanoTime();
|
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();
|
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) + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,8 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class ClassicIoUnbuffered {
|
public class ClassicIoUnbuffered {
|
||||||
|
|
||||||
private static int lineCount(String path){
|
private static int lineCount(String path, boolean doDance){
|
||||||
|
if ( ! doDance ) return -1;
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
try {
|
try {
|
||||||
fis = new FileInputStream(path);
|
fis = new FileInputStream(path);
|
||||||
@@ -23,11 +24,6 @@ public class ClassicIoUnbuffered {
|
|||||||
while ((b = fis.read()) != -1) {
|
while ((b = fis.read()) != -1) {
|
||||||
if (b == '\n') cnt++;
|
if (b == '\n') cnt++;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
fis.close();
|
fis.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
@@ -38,9 +34,13 @@ public class ClassicIoUnbuffered {
|
|||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
long startTime = System.nanoTime();
|
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();
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,8 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class ClassicIoWholeFile {
|
public class ClassicIoWholeFile {
|
||||||
|
|
||||||
public static int lineCount(String path){
|
private static int lineCount(String path, boolean doDance){
|
||||||
|
if ( ! doDance ) return -1;
|
||||||
int len = (int)(new File(path).length());
|
int len = (int)(new File(path).length());
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
FileInputStream fis;
|
FileInputStream fis;
|
||||||
@@ -39,9 +40,13 @@ public class ClassicIoWholeFile {
|
|||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
long startTime = System.nanoTime();
|
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();
|
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) + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user