前日在用SiSoftware Sandra 测试硬盘性能时突发其想用自己熟悉的VBNET测试行不行呢?具体怎么做呢?
我们最感兴趣的是硬盘在最大负荷下持续的读取和写入速度为了能够比较准确的测出平均速度我决定采用先写入一个GB的文件再读取出来的办法考虑到不要让更多的任务花在循环上我首先建立起一个足够大的缓沖区然后往磁盘写入这个缓沖的内容从而使硬盘达到最大的负荷考虑到Windows的读取机制硬盘测试不太准确此程序的读取部分只能在第一次运行时使用运行次数越多测试也不准确而写入测试多次运行以后依然能够保持准确性现在就开始动手
在VBNET中创建了一个控制台工程TestHarddisk然后在Sub Main中写入下列程序
Sub Main()
Dim I As Int
Dim f As New FileStream(E:\BigFilebig FileModeCreate)
Dim fw As New BinaryWriter(f)
Dim fr As New BinaryReader(f)
Dim Size As Int = * * File size = GB
Dim bufSize As Int = * * Buffer Size = MB
Dim jLast As Int = bufSize
Dim j As Int
Dim Bytes(bufSize) As Byte
Dim StartWrite As Date = DateNow
ConsoleWriteLine(Write Start at {} StartWrite)
ConsoleWriteLine(Creating)
For I = To Size Step bufSize GB
fwWrite(Bytes)
Next
Dim EndWrite As Date = DateNow
Dim TimePassed As TimeSpan = EndWriteSubtract(StartWrite)
ConsoleWriteLine(Write End at {} EndWrite)
ConsoleWriteLine(Time passed:{} TimePassed)
ConsoleWriteLine(Speed:{} / TimePassedTotalSeconds)
fwFlush()
Dim StartRead As Date = DateNow
ConsoleWriteLine(Read Start at {} StartRead)
ConsoleWriteLine(Reading)
For I = To Size Step bufSize
Bytes = frReadBytes(bufSize)
Next
Dim EndRead As Date = DateNow
TimePassed = EndReadSubtract(StartRead)
ConsoleWriteLine(Read End at {} EndRead)
ConsoleWriteLine(Time passed:{} TimePassed)
ConsoleWriteLine(Read speed:{} / TimePassedTotalSeconds)
ConsoleReadLine()
fwClose()
End Sub
现在测试
硬件配置
Athlon +(running at G)
EPOX RDA+ nForce主板
DDR (running at MHz)
ATA Seagate GB MB
软件配置
Windows Server Standard Edition
全套最新的WHQL驱动程序
Visual Studio 编译选择Realse模式打开所有优化选项
第一次运行测试得写入速度MB/s第二次测得MB/s第三次MB/s与Sisoftware测试得的结果MB/s相差不大达到了理想的效果然而读取测试就变态了第一次MB/s与Sissoftware测试多了MB/s左右第二次达到了MB/s第三次MB/s这和Windows的磁盘缓沖机制有关看来作用还是蛮大的当然建议读取测试在重起电脑以后进行