module1.vb

来自「硬盘速度测试」· VB 代码 · 共 53 行

VB
53
字号
Imports System.IO


Module Module1


    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 Date = 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 Date = 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 Date = 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 Date = 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

End Module

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?