06-24-2024, 05:19 AM
I'm trying to build a prog to compare different sorting algorithms (yes, I know it's been done a zillion times).
But when I try to use Timer to find the execution time, it seems to go back to the Start time, giving me expired time of zero.
I've experimented with _Limit, to see if the system was having problems keeping up or something, and these give some expired time,
but these depend on what _limit I use, so they alter the readings.
In the small sample here, what am I missing?
But when I try to use Timer to find the execution time, it seems to go back to the Start time, giving me expired time of zero.
I've experimented with _Limit, to see if the system was having problems keeping up or something, and these give some expired time,
but these depend on what _limit I use, so they alter the readings.
In the small sample here, what am I missing?
Code: (Select All)
DefDbl T
Randomize Timer
MakeList:
Print Tab(30); "Create 104 Unsorted elements (4 sets A to Z)"
Dim EL$(104)
For a = 1 To 26
For b = 0 To 3
EL$(a + b * 26) = Chr$(Int(Rnd * 26) + 65)
Print EL$(a + b * 26); " ";
Next
Next
T1 = Timer ' start time
Print: Print "Start time is"; T1
BubbleSort:
pass = pass + 1
For a = 1 To UBound(EL$) - 1 ' for first element to last-1 element of Orig$() array
' _Limit 30
'_limit 300
'_limit 3000
' _Limit 30000
If EL$(a) > EL$(a + 1) Then ' if this element is greater than next element, swap them,
Swap EL$(a), EL$(a + 1)
swop = 1 ' and flag that a swap was made in this pass
End If
Next
If swop = 1 Then swop = 0: GoTo BubbleSort '
T2 = Timer ' finish time
Print: Print "Finish time is"; T2
For a = 1 To 104: Print EL$(a); " ";: Next
Print: Print: Print "T1 is"; T1, "T2 is"; T2
Print: Print Tab(10); "Sorted in "; T2 - T1; "seconds, with "; pass; "passes"
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)
Please visit my Website at: http://oldendayskids.blogspot.com/
Please visit my Website at: http://oldendayskids.blogspot.com/