Основы офисного программирования и язык VBA


Пример 8.7


Public Sub Speed()

'Эта программа выполняет замеры времени вычислений над данными разного типа

Dim Start As Single, Finish As Single

Dim i As Long, j As Long

Dim bx As Byte, by As Byte, bz As Byte

Dim ix As Integer, iy As Integer, iz As Integer

Dim lx As Long, ly As Long, lz As Long

Dim sx As Single, sy As Single, sz As Single

Dim dx As Double, dy As Double, dz As Double

For i = 1 To 5 'Внешний цикл для повторения замеров времени

Start = Timer

For j = 1 To 100000

bx = 99: by = 101

bz = by * (by - bx) \ by

Next j

Finish = Timer

Debug.Print "Тип Byte: Время ", i, " = ", Finish - Start

Debug.Print "bz = ", bz

Start = Timer

For j = 1 To 100000

ix = 99: iy = 101

iz = iy * (iy - ix) \ iy

Next j

Finish = Timer

Debug.Print "Тип Integer: Время ", i, " = ", Finish - Start

Debug.Print "iz = ", iz

Start = Timer

For j = 1 To 100000

lx = 99: ly = 101

lz = ly * (ly - lx) \ ly

Next j

Finish = Timer

Debug.Print "Тип Long: Время ", i, " = ", Finish - Start

Debug.Print "lz = ", lz

Start = Timer

For j = 1 To 100000

sx = 99: sy = 101

sz = sy * (sy - sx) / sy

Next j

Finish = Timer

Debug.Print "Тип Single: Время ", i, " = ", Finish - Start

Debug.Print "sz = ", sz

Start = Timer

For j = 1 To 100000

dx = 99: dy = 101

dz = dy * (dy - dx) / dy

Next j

Finish = Timer

Debug.Print "Тип Double: Время ", i, " = ", Finish - Start

Debug.Print "dz = ", dz

Next i

End Sub




Начало  Назад  Вперед