我正在尝试确定将二进制文件从一个位置保存到另一个位置所需的速度或速度。
FileInputStream fis = new FileInputStream("/path/to/binary/file");
BufferedInputStream in = new BufferedInputStream(fis);
FileOutputStream fos = new FileOutputStream("/path/to/save/new/binary/file");
BufferedOutputStream out = new BufferedOutputStream(fos);
long before = System.currentTimeMillis();
int data = 0;
while ((data = in.read()) != -1) {
out.write(data);
}
in.close();
out.close();
int seconds = (int) (System.currentTimeMillis() - before / 1000) % 60;
System.out.println("Took " + seconds);
缓冲或无缓冲,输出范围为3到64 ms。我本来期望更近的范围,例如40-50或10-20,或30-40。造成这种高波动的原因是什么?
答案 0 :(得分:2)
答案 1 :(得分:0)
文件I / O可能涉及很多“随机性”:
查看 cheeken 关于如何处理此问题的建议。