您好,登錄后才能下訂單哦!
這篇文章給大家介紹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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。