这篇文章给大家介绍VB.NET硬盘速度测试的应用方法是什么,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
我们最感兴趣的是硬盘在***负荷下持续的读取和写入速度。为了能够比较准确的测出平均速度,我决定采用先写入一个1GB的文件再读取出来的办法。考虑到不要让更多的任务花在循环上,我首先建立起一个足够大的缓冲区,然后往磁盘写入这个缓冲的内容,从而使硬盘达到***的负荷。考虑到Windows的读取机制,硬盘测试不太准确,此程序的读取部分只能在***次运行时使用,运行次数越多测试也不准确,而写入测试多次运行以后依然能够保持准确性。现在就开始动手。
在VB.NET中创建了一个控制台工程TestHarddisk,然后在Sub Main中写入下列VB.NET硬盘速度测试程序。
Sub Main()
Dim I As Int32
Dim f As New FileStream("E:\BigFile.
big", FileMode.Create)Dim fw As New BinaryWriter(f)
Dim fr As New BinaryReader(f)
Dim Size As Int32 = 1024 * 1024 *
1024 - 1 'File size = 1GBDim bufSize As Int32 = 30 * 1024 *
1024 'Buffer Size = 30MBDim jLast As Int32 = bufSize - 1
Dim j As Int32
Dim Bytes(bufSize) As Byte
Dim StartWrite As DateDate = Date.Now
Console.WriteLine("Write Start at
{0}", StartWrite)Console.WriteLine("Creating...")
For I = 0 To Size Step bufSize '1GB
fw.Write(Bytes)
Next
Dim EndWrite As DateDate = Date.Now
Dim TimePassed As TimeSpan = EndWrite.
Subtract(StartWrite)Console.WriteLine("Write End at
{0}", EndWrite)Console.WriteLine("Time passed:{0}",
TimePassed)Console.WriteLine("Speed:{0}", 1000
/ TimePassed.TotalSeconds)fw.Flush()
Dim StartRead As DateDate = Date.Now
Console.WriteLine("Read Start at
{0}", StartRead)Console.WriteLine("Reading")
For I = 0 To Size Step bufSize
Bytes = fr.ReadBytes(bufSize)
Next
Dim EndRead As DateDate = Date.Now
TimePassed = EndRead.Subtract(StartRead)
Console.WriteLine("Read End at {0}", EndRead)
Console.WriteLine("Time passed:
{0}", TimePassed)Console.WriteLine("Read speed:{0}",
1000 / TimePassed.TotalSeconds)Console.ReadLine()
fw.Close()
End Sub
VB.NET硬盘速度测试的相关测试方法如上面这段代码所示。
关于VB.NET硬盘速度测试的应用方法是什么就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。