我有10个文件,每个文件是500M。
我使用Long randomValue = Math.abs(random.nextLong());
生成这些文件。文件中的每一行都是randomValue。一个文件大约有26374000行。
当我在另一个程序中逐个读取这些文件并计算成本时间时,我发现输入变得更快。为什么?
read 0 file 26373542 lines time : 27046ms
read 1 file 26373627 lines time : 24155ms
read 2 file 26373676 lines time : 19227ms
read 3 file 26373768 lines time : 22875ms
read 4 file 26373681 lines time : 20813ms
read 5 file 26373774 lines time : 18297ms
read 6 file 26373787 lines time : 10556ms
read 7 file 26373557 lines time : 11614ms
read 8 file 26373566 lines time : 9751ms
read 9 file 26373653 lines time : 13372ms
这是我的计划:
Long start = new Date().getTime();
FileReader fr = new FileReader(inFile);
BufferedReader br = new BufferedReader(fr);
String num;
while((num = br.readLine()) != null) {
sorted[j++] = Long.parseLong(num);
count++;
}
Long end = new Date().getTime();
System.out.println("read " + i + " file " + j + "lines time : " + (mid - start) + "ms");
br.close();
fr.close();
答案 0 :(得分:0)
一些事情: