VB.NET硬盤速度測(cè)試詳細(xì)應(yīng)用方法介紹
學(xué)習(xí)VB.NET的朋友們應(yīng)該都會(huì)知道,其在移動(dòng)設(shè)備的操作方面展現(xiàn)了非常大的優(yōu)勢(shì)。在這里我們就會(huì)為大家詳細(xì)介紹一下有關(guān)VB.NET硬盤速度測(cè)試的相關(guān)方法,希望能給大家?guī)硪恍椭?t#
我們最感興趣的是硬盤在***負(fù)荷下持續(xù)的讀取和寫入速度。為了能夠比較準(zhǔn)確的測(cè)出平均速度,我決定采用先寫入一個(gè)1GB的文件再讀取出來的辦法??紤]到不要讓更多的任務(wù)花在循環(huán)上,我首先建立起一個(gè)足夠大的緩沖區(qū),然后往磁盤寫入這個(gè)緩沖的內(nèi)容,從而使硬盤達(dá)到***的負(fù)荷??紤]到Windows的讀取機(jī)制,硬盤測(cè)試不太準(zhǔn)確,此程序的讀取部分只能在***次運(yùn)行時(shí)使用,運(yùn)行次數(shù)越多測(cè)試也不準(zhǔn)確,而寫入測(cè)試多次運(yùn)行以后依然能夠保持準(zhǔn)確性?,F(xiàn)在就開始動(dòng)手。
在VB.NET中創(chuàng)建了一個(gè)控制臺(tái)工程TestHarddisk,然后在Sub Main中寫入下列VB.NET硬盤速度測(cè)試程序。
- 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 = 1GB- Dim bufSize As Int32 = 30 * 1024 *
1024 'Buffer Size = 30MB- Dim 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硬盤速度測(cè)試的相關(guān)測(cè)試方法如上面這段代碼所示。