TestMath




Dim TimeUp As Boolean
Dim Str As String
Private Sub cmdAdditions_Click()
' set to loading mousepointer

MousePointer = vbHourglass
' first do floating point

Dim Float1 As Single
Dim Float2 As Single
Dim Float3 As Single
Dim FloatsDone As Long
Timer1.Enabled = True
FloatsDone = 0
Float1 = Rnd * 100000
Float2 = Rnd * 100000
TimeUp = False
Do
DoEvents
Float3 = Float1 + Float2
FloatsDone = FloatsDone + 1
Loop Until TimeUp = True
' now do fixed point

Dim Fixed1 As Long
Dim Fixed2 As Long
Dim Fixed3 As Long
Dim FixedsDone As Long
Timer1.Enabled = True
FixedsDone = 0
Fixed1 = Rnd * 100000
Fixed2 = Rnd * 100000
TimeUp = False
Do
DoEvents
Fixed3 = Fixed1 + Fixed2
FixedsDone = FixedsDone + 1
Loop Until TimeUp = True
' set to normal mousepointer

MousePointer = vbDefault
'display results

Str = "Results : " & FloatsDone & " floating point additions versus " & FixedsDone & " fixed point additions done."
MsgBox Str, vbInformation, "Results for addition"
Text1.Text = Text1.Text & (Chr(13) + Chr(10)) & Str
End Sub

Private Sub cmdDivides_Click()
' set to loading mousepointer

MousePointer = vbHourglass
' first do floating point

Dim Float1 As Single
Dim Float2 As Single
Dim Float3 As Single
Dim FloatsDone As Long
Timer1.Enabled = True
FloatsDone = 0
Float1 = Rnd * 100000
Float2 = Rnd * 100000
TimeUp = False
Do
DoEvents
Float3 = Float1 / Float2
FloatsDone = FloatsDone + 1
Loop Until TimeUp = True
' now do fixed point

Dim Fixed1 As Long
Dim Fixed2 As Long
Dim Fixed3 As Long
Dim FixedsDone As Long
Timer1.Enabled = True
FixedsDone = 0
Fixed1 = Rnd * 100000
Fixed2 = Rnd * 100000
TimeUp = False
Do
DoEvents
Fixed3 = Fixed1 \ Fixed2
FixedsDone = FixedsDone + 1
Loop Until TimeUp = True
' set to normal mousepointer

MousePointer = vbDefault
'display results

Str = "Results : " & FloatsDone & " floating point subtractions versus " & FixedsDone & " fixed point subtractions done."
MsgBox Str, vbInformation, "Results for subtraction"
Text1.Text = Text1.Text & (Chr(13) + Chr(10)) & Str
End Sub

Private Sub cmdMult_Click()
'set to loading mousepointer

MousePointer = vbHourglass
'first do floating point

Dim Float1 As Single
Dim Float2 As Single
Dim Float3 As Single
Dim FloatsDone As Long
Timer1.Enabled = True
FloatsDone = 0
Float1 = Rnd * 1000
Float2 = Rnd * 1000
TimeUp = False
Do
DoEvents
Float3 = Float1 * Float2
FloatsDone = FloatsDone + 1
Loop Until TimeUp = True
'now do fixed point

Dim Fixed1 As Long
Dim Fixed2 As Long
Dim Fixed3 As Long
Dim FixedsDone As Long
Timer1.Enabled = True
FixedsDone = 0
Fixed1 = Rnd * 1000
Fixed2 = Rnd * 1000
TimeUp = False
Do
DoEvents
Fixed3 = Fixed1 * Fixed2
FixedsDone = FixedsDone + 1
Loop Until TimeUp = True
'set to normal mousepointer

MousePointer = vbDefault
'display results

Str = "Results : " & FloatsDone & " floating point multiplications versus " & FixedsDone & " fixed point multiplications done."
MsgBox Str, vbInformation, "Results for multiplication"
Text1.Text = Text1.Text & (Chr(13) + Chr(10)) & Str
End Sub

Private Sub cmdSubtractions_Click()
'set to loading mousepointer

MousePointer = vbHourglass
'first do floating point

Dim Float1 As Single
Dim Float2 As Single
Dim Float3 As Single
Dim FloatsDone As Long
Timer1.Enabled = True
FloatsDone = 0
Float1 = Rnd * 100000
Float2 = Rnd * 100000
TimeUp = False
Do
DoEvents
Float3 = Float1 - Float2
FloatsDone = FloatsDone + 1
Loop Until TimeUp = True
'now do fixed point

Dim Fixed1 As Long
Dim Fixed2 As Long
Dim Fixed3 As Long
Dim FixedsDone As Long
Timer1.Enabled = True
FixedsDone = 0
Fixed1 = Rnd * 100000
Fixed2 = Rnd * 100000
TimeUp = False

Do
DoEvents
Fixed3 = Fixed1 - Fixed2
FixedsDone = FixedsDone + 1
Loop Until TimeUp = True
'set to normal mousepointer

MousePointer = vbDefault
'display results

Str = "Results : " & FloatsDone & " floating point divides versus " & FixedsDone & " fixed point divides done."
MsgBox Str, vbInformation, "Results for division"
Text1.Text = Text1.Text & (Chr(13) + Chr(10)) & Str
End Sub

Private Sub Timer1_Timer()
TimeUp = True
Timer1.Enabled = False
End Sub

Dim TimeUp As Boolean
Dim Str As String
Private Sub cmdAdditions_Click()
' set to loading mousepointer

MousePointer = vbHourglass
' first do floating point

Dim Float1 As Single
Dim Float2 As Single
Dim Float3 As Single
Dim FloatsDone As Long
Timer1.Enabled = True
FloatsDone = 0
Float1 = Rnd * 100000
Float2 = Rnd * 100000
TimeUp = False
Do
DoEvents
Float3 = Float1 + Float2
FloatsDone = FloatsDone + 1
Loop Until TimeUp = True
' now do fixed point

Dim Fixed1 As Long
Dim Fixed2 As Long
Dim Fixed3 As Long
Dim FixedsDone As Long
Timer1.Enabled = True
FixedsDone = 0
Fixed1 = Rnd * 100000
Fixed2 = Rnd * 100000
TimeUp = False
Do
DoEvents
Fixed3 = Fixed1 + Fixed2
FixedsDone = FixedsDone + 1
Loop Until TimeUp = True
' set to normal mousepointer

MousePointer = vbDefault
'display results

Str = "Results : " & FloatsDone & " floating point additions versus " & FixedsDone & " fixed point additions done."
MsgBox Str, vbInformation, "Results for addition"
Text1.Text = Text1.Text & (Chr(13) + Chr(10)) & Str
End Sub

Private Sub cmdDivides_Click()
' set to loading mousepointer

MousePointer = vbHourglass
' first do floating point

Dim Float1 As Single
Dim Float2 As Single
Dim Float3 As Single
Dim FloatsDone As Long
Timer1.Enabled = True
FloatsDone = 0
Float1 = Rnd * 100000
Float2 = Rnd * 100000
TimeUp = False
Do
DoEvents
Float3 = Float1 / Float2
FloatsDone = FloatsDone + 1
Loop Until TimeUp = True
' now do fixed point

Dim Fixed1 As Long
Dim Fixed2 As Long
Dim Fixed3 As Long
Dim FixedsDone As Long
Timer1.Enabled = True
FixedsDone = 0
Fixed1 = Rnd * 100000
Fixed2 = Rnd * 100000
TimeUp = False
Do
DoEvents
Fixed3 = Fixed1 \ Fixed2
FixedsDone = FixedsDone + 1
Loop Until TimeUp = True
' set to normal mousepointer

MousePointer = vbDefault
'display results

Str = "Results : " & FloatsDone & " floating point subtractions versus " & FixedsDone & " fixed point subtractions done."
MsgBox Str, vbInformation, "Results for subtraction"
Text1.Text = Text1.Text & (Chr(13) + Chr(10)) & Str
End Sub

Private Sub cmdMult_Click()
'set to loading mousepointer

MousePointer = vbHourglass
'first do floating point

Dim Float1 As Single
Dim Float2 As Single
Dim Float3 As Single
Dim FloatsDone As Long
Timer1.Enabled = True
FloatsDone = 0
Float1 = Rnd * 1000
Float2 = Rnd * 1000
TimeUp = False
Do
DoEvents
Float3 = Float1 * Float2
FloatsDone = FloatsDone + 1
Loop Until TimeUp = True
'now do fixed point

Dim Fixed1 As Long
Dim Fixed2 As Long
Dim Fixed3 As Long
Dim FixedsDone As Long
Timer1.Enabled = True
FixedsDone = 0
Fixed1 = Rnd * 1000
Fixed2 = Rnd * 1000
TimeUp = False
Do
DoEvents
Fixed3 = Fixed1 * Fixed2
FixedsDone = FixedsDone + 1
Loop Until TimeUp = True
'set to normal mousepointer

MousePointer = vbDefault
'display results

Str = "Results : " & FloatsDone & " floating point multiplications versus " & FixedsDone & " fixed point multiplications done."
MsgBox Str, vbInformation, "Results for multiplication"
Text1.Text = Text1.Text & (Chr(13) + Chr(10)) & Str
End Sub

Private Sub cmdSubtractions_Click()
'set to loading mousepointer

MousePointer = vbHourglass
'first do floating point

Dim Float1 As Single
Dim Float2 As Single
Dim Float3 As Single
Dim FloatsDone As Long
Timer1.Enabled = True
FloatsDone = 0
Float1 = Rnd * 100000
Float2 = Rnd * 100000
TimeUp = False
Do
DoEvents
Float3 = Float1 - Float2
FloatsDone = FloatsDone + 1
Loop Until TimeUp = True
'now do fixed point

Dim Fixed1 As Long
Dim Fixed2 As Long
Dim Fixed3 As Long
Dim FixedsDone As Long
Timer1.Enabled = True
FixedsDone = 0
Fixed1 = Rnd * 100000
Fixed2 = Rnd * 100000
TimeUp = False

Do
DoEvents
Fixed3 = Fixed1 - Fixed2
FixedsDone = FixedsDone + 1
Loop Until TimeUp = True
'set to normal mousepointer

MousePointer = vbDefault
'display results

Str = "Results : " & FloatsDone & " floating point divides versus " & FixedsDone & " fixed point divides done."
MsgBox Str, vbInformation, "Results for division"
Text1.Text = Text1.Text & (Chr(13) + Chr(10)) & Str
End Sub

Private Sub Timer1_Timer()
TimeUp = True
Timer1.Enabled = False
End Sub











( testmath.html )- by Paolo Puglisi - Modifica del 17/12/2023