バイナリファイルをある場所から別の場所に保存するのにどれくらいの時間がかかっているかをベンチマークしようとしています。高い変動を出力するマイクロベンチマーク
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といったもっと近い範囲を期待していたでしょう。この高い変動の原因は何ですか?
nanoTimeを使用すると、currentTimeMillisと同じ結果が得られます。だから私は複数のテストを実行し、そこから平均を取得する必要があります。 –