For testing speed you can use the stop watch class. It's great for figuring out the most efficient code. For example:
Dim sw As New Stopwatch
sw.start()
For x As Integer = 1 To 100000
Next
sw.stop()
MsgBox("Ticks elapsed " & sw.ElapsedTicks)</pre>That being said I ran each piece of code in a loop. It looped 10000 times and I ran each test 3 times writing down how many ticks the loop took. Note: I only used the bare if structure. I obviously couldn't display a message box 10000 times. The results are:<pre>Without a Winner:
First Method: 9617458 ticks on average (About 4.5% faster)
Second Method: 10075610 ticks on average
With a Winner (First Row)
FYI - I only tested the first row which should give the biggest difference
First Method: 8536682 ticks on average
Second Method: 2422805 ticks on average (About 71% faster)
This code however I also tested and it performed the fastest.
If (btn1.Text = "X" AndAlso btn2.Text = "X" AndAlso btn3.Text = "X") _
OrElse (btn4.Text = "X" AndAlso btn5.Text = "X" AndAlso btn6.Text = "X") _
OrElse (btn7.Text = "X" AndAlso btn8.Text = "X" AndAlso btn9.Text = "X") Then
'Show player X won
End If
Compared to the faster methods the results are:
Without a Winner:
Third Option: 3262610 Ticks on average (About 66% faster)
With a Winner (First Row)
Third Option: 2278090 Ticks on average (About 6% faster)
Enter your message below
Sign in or Join us (it's free).