VB.NET硬盘速度测试详细应用方法介绍

开发 后端
其实使用VB.NET进行硬盘速度测试,可以得到更精准的数据,实现起来也是比较简单的。下面我们就一起来看看具体的操作方法。

学习VB.NET的朋友们应该都会知道,其在移动设备的操作方面展现了非常大的优势。在这里我们就会为大家详细介绍一下有关VB.NET硬盘速度测试的相关方法,希望能给大家带来一些帮助。#t#

我们最感兴趣的是硬盘在***负荷下持续的读取和写入速度。为了能够比较准确的测出平均速度,我决定采用先写入一个1GB的文件再读取出来的办法。考虑到不要让更多的任务花在循环上,我首先建立起一个足够大的缓冲区,然后往磁盘写入这个缓冲的内容,从而使硬盘达到***的负荷。考虑到Windows的读取机制,硬盘测试不太准确,此程序的读取部分只能在***次运行时使用,运行次数越多测试也不准确,而写入测试多次运行以后依然能够保持准确性。现在就开始动手。

在VB.NET中创建了一个控制台工程TestHarddisk,然后在Sub Main中写入下列VB.NET硬盘速度测试程序。

  1. Sub Main()  
  2. Dim I As Int32  
  3. Dim f As New FileStream("E:\BigFile.
    big", FileMode.Create)  
  4. Dim fw As New BinaryWriter(f)  
  5. Dim fr As New BinaryReader(f)  
  6. Dim Size As Int32 = 1024 * 1024 * 
    1024 - 1 'File 
    size = 1GB 
  7. Dim bufSize As Int32 = 30 * 1024 * 
    1024 'Buffer 
    Size = 30MB 
  8. Dim jLast As Int32 = bufSize - 1  
  9. Dim j As Int32  
  10. Dim Bytes(bufSize) As Byte  
  11. Dim StartWrite As DateDate = Date.Now  
  12. Console.WriteLine("Write Start at 
    {0}", StartWrite)  
  13. Console.WriteLine("Creating...")  
  14. For I = 0 To Size Step bufSize '1GB  
  15. fw.Write(Bytes)  
  16. Next  
  17. Dim EndWrite As DateDate = Date.Now  
  18. Dim TimePassed As TimeSpan = EndWrite.
    Subtract(StartWrite)  
  19. Console.WriteLine("Write End at 
    {0}", EndWrite)  
  20. Console.WriteLine("Time passed:{0}",
     TimePassed)  
  21. Console.WriteLine("Speed:{0}", 1000 
    / TimePassed.TotalSeconds)  
  22. fw.Flush()  
  23. Dim StartRead As DateDate = Date.Now  
  24. Console.WriteLine("Read Start at 
    {0}", StartRead)  
  25. Console.WriteLine("Reading")  
  26. For I = 0 To Size Step bufSize  
  27. Bytes = fr.ReadBytes(bufSize)  
  28. Next  
  29. Dim EndRead As DateDate = Date.Now  
  30. TimePassed = EndRead.Subtract(StartRead)  
  31. Console.WriteLine("Read End at {0}", EndRead)  
  32. Console.WriteLine("Time passed:
    {0}", TimePassed)  
  33. Console.WriteLine("Read speed:{0}", 
    1000 / TimePassed.TotalSeconds)  
  34. Console.ReadLine()  
  35. fw.Close()  
  36. End Sub  

VB.NET硬盘速度测试的相关测试方法如上面这段代码所示。

责任编辑:曹凯 来源: 中国IT实验室
相关推荐

2010-01-08 14:50:47

VB.NET测试硬盘速

2009-11-10 12:42:47

VB.NET Prin

2010-01-07 15:25:11

VB.NET数组

2010-01-08 13:35:35

VB.NET写Log方

2009-10-28 09:55:29

VB.NET MyCl

2010-01-21 16:45:00

VB.NET继承规则

2009-10-12 15:02:51

VB.NET动态控件

2010-01-08 14:14:27

VB.NET使用Fin

2010-01-15 10:56:50

VB.NET继承实现多

2010-01-07 18:17:00

VB.NET连接SAP

2010-01-22 10:41:33

VB.NET声明结构

2010-01-18 17:09:52

VB.NET创建虚拟目

2009-10-15 15:04:42

VB.NET PadL

2010-01-08 15:03:12

VB.NET类属性

2010-01-08 09:43:21

VB.NET汉字转换

2009-11-10 12:48:17

VB.NET三维模型

2010-01-07 16:08:45

VB.NET子过程和函

2010-01-15 18:12:28

VB.NET超链接

2010-01-21 17:58:40

VB.NET List

2010-01-15 19:17:23

点赞
收藏

51CTO技术栈公众号