這篇文章給大家介紹VB.NET硬盤速度測試的應(yīng)用方法是什么,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、成都微信小程序、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了巫山免費(fèi)建站歡迎大家使用!
我們最感興趣的是硬盤在***負(fù)荷下持續(xù)的讀取和寫入速度。為了能夠比較準(zhǔn)確的測出平均速度,我決定采用先寫入一個(gè)1GB的文件再讀取出來的辦法??紤]到不要讓更多的任務(wù)花在循環(huán)上,我首先建立起一個(gè)足夠大的緩沖區(qū),然后往磁盤寫入這個(gè)緩沖的內(nèi)容,從而使硬盤達(dá)到***的負(fù)荷??紤]到Windows的讀取機(jī)制,硬盤測試不太準(zhǔn)確,此程序的讀取部分只能在***次運(yùn)行時(shí)使用,運(yùn)行次數(shù)越多測試也不準(zhǔn)確,而寫入測試多次運(yùn)行以后依然能夠保持準(zhǔn)確性。現(xiàn)在就開始動(dòng)手。
在VB.NET中創(chuàng)建了一個(gè)控制臺工程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硬盤速度測試的相關(guān)測試方法如上面這段代碼所示。
關(guān)于VB.NET硬盤速度測試的應(yīng)用方法是什么就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。