Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Which is the fastest?

$
0
0

Hello, I am experimenting with "If" & "Switch" to determine which method is faster...

 

I am currently using this script to test them:

AutoIt         
  1. Global $number = Random(0 , 10, 1)
  2. Global $pass = False
  3.  
  4. Global $time_if = TimerInit()
  5. For $i = 0 To $number
  6.     If $i = $number Then $pass = True
  7.  
  8. $time_if = TimerDiff($time_if)
  9. MsgBox(64, "Timer", '"If" took ' & $time_if & ' milli-seconds.')
  10. $pass = False
  11.  
  12. Global $time_switch = TimerInit()
  13.  
  14. Switch $number
  15.     Case 0
  16.         $pass = True
  17.        
  18.     Case 1
  19.         $pass = True
  20.    
  21.     Case 2
  22.         $pass = True
  23.        
  24.     Case 3
  25.         $pass = True
  26.        
  27.     Case 4
  28.         $pass = True
  29.        
  30.     Case 5
  31.         $pass = True
  32.        
  33.     Case 6
  34.         $pass = True
  35.        
  36.     Case 7
  37.         $pass = True
  38.        
  39.     Case 8
  40.         $pass = True
  41.        
  42.     Case 9
  43.         $pass = True
  44.        
  45.     Case 10
  46.         $pass = True
  47.        
  48.  
  49. $time_switch = TimerDiff($time_switch)
  50. MsgBox(64, "Timer", '"Switch" took ' & $time_if & ' milli-seconds.')
  51.  
  52. MsgBox(64, "The winner is...", "The winner is...", 3)
  53.  
  54. If $time_if < $time_switch Then
  55.     MsgBox(64, "The winner is... If!!!", "The winner is... If!!!")
  56.     Global $diff = $time_switch - $time_if
  57.     MsgBox(64, "The winner is... Switch!!!", "The winner is... Switch!!!")
  58.     Global $diff = $time_if - $time_switch
  59.  
  60. MsgBox(64, "Intel", "The difference was only " & $diff & " milliseconds.")

Sometimes "Switch" wins, Sometimes "If" wins...

 

Thanks in Advance :)


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>