熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

VB.NET編寫測試硬盤速度的程序

2022-06-13   來源: .NET編程 

  前日在用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的磁盤緩沖機制有關看來作用還是蠻大的當然建議讀取測試在重起電腦以後進行

From:http://tw.wingwit.com/Article/program/net/201311/13666.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.