我想知道如何使用Java API来测量磁盘速度。可以衡量的有随机读、顺序读和随机和顺序写。
如果有人认为这不是一个真正的问题,请在关闭前解释一下。
谢谢
如果有人认为这不是一个真正的问题,请在关闭前解释一下。
谢谢
https://sourceforge.net/projects/jdiskmark/
这里是写入测量代码的片段:try (RandomAccessFile rAccFile = new RandomAccessFile(testFile,mode)) {
for (int b=0; b<numOfBlocks; b++) {
if (App.randomEnable) {
int rLoc = Util.randInt(0, numOfBlocks-1);
rAccFile.seek(rLoc*blockSize);
} else {
rAccFile.seek(b*blockSize);
}
rAccFile.write(blockArr, 0, blockSize);
totalBytesWrittenInMark += blockSize;
wUnitsComplete++;
unitsComplete = rUnitsComplete + wUnitsComplete;
percentComplete = (float)unitsComplete/(float)unitsTotal * 100f;
}
}
long endTime = System.nanoTime();
long elapsedTimeNs = endTime - startTime;
double sec = (double)elapsedTimeNs / (double)1000000000;
double mbWritten = (double)totalBytesWrittenInMark / (double)MEGABYTE;
long bwMbSec = mbWritten / sec;
System.out.println("Write IO is " + bwMbSec + " MB/s"
+ "(MB written " + mbWritten + " in " + sec + " sec)");
public class MyBenchmark extends SimpleBenchmark {
public void timeMyOperation(int reps) {
for (int i = 0; i < reps; i++) {
MyClass.myOperation();
}
}
}