Spider001 Posted December 3, 2014 Share Posted December 3, 2014 (edited) hey can someone tell me what's faster $i = 1 While $i <= 1000 $i += 1 WEnd or For $i = 1 To 1000 Step 1 $j += 1 Next thank you Edited December 3, 2014 by Spider001 Link to comment Share on other sites More sharing options...
mikell Posted December 3, 2014 Share Posted December 3, 2014 You should consider that the purpose is to do something in the loop, increment $j in this case $j = 0 $hTimer = TimerInit() $i = 1 While $i<=1000 $i += 1 $j += 1 Wend $fDiff1 = TimerDiff($hTimer) $j = 0 $hTimer = TimerInit() For $i = 1 To 1000 $j += 1 Next $fDiff2 = TimerDiff($hTimer) Msgbox(0,"", $fDiff1 & @crlf & $fDiff2) Link to comment Share on other sites More sharing options...
Spider001 Posted December 3, 2014 Author Share Posted December 3, 2014 (edited) just did something FOR is faster Local $hTimer = TimerInit() $i = 1 While $i <= 1000 $i += 1 WEnd ConsoleWrite(TimerDiff($hTimer) & @CRLF) Local $hTimer = TimerInit() Local $j For $i = 1 To 1000 Step 1 $j += 1 Next ConsoleWrite(TimerDiff($hTimer) & @CRLF) 1.26831762137367 0.445866723284663 and this is a simple thing Edited December 3, 2014 by Spider001 Link to comment Share on other sites More sharing options...
Spider001 Posted December 3, 2014 Author Share Posted December 3, 2014 (edited) You should consider that the purpose is to do something in the loop, increment $j in this case $j = 0 $hTimer = TimerInit() $i = 1 While $i<=1000 $i += 1 $j += 1 Wend $fDiff1 = TimerDiff($hTimer) $j = 0 $hTimer = TimerInit() For $i = 1 To 1000 $j += 1 Next $fDiff2 = TimerDiff($hTimer) Msgbox(0,"", $fDiff1 & @crlf & $fDiff2) your example give the same FOR is faster 1.45660970877584 0.433015928002023 While $i<=1000 $i += 1 Wend 1.08589220138314 0.441117516332383 Edited December 3, 2014 by Spider001 Link to comment Share on other sites More sharing options...
mikell Posted December 3, 2014 Share Posted December 3, 2014 Yes If $i is the local var only used to step inside the loop, your example should be Local $hTimer = TimerInit() $i = 1 While $i <= 1000 $i += 1 WEnd ConsoleWrite(TimerDiff($hTimer) & @CRLF) Local $hTimer = TimerInit() Local $j For $i = 1 To 1000 Step 1 ; $j += 1 Next ConsoleWrite(TimerDiff($hTimer) & @CRLF) And the answer is even more obvious Link to comment Share on other sites More sharing options...
Spider001 Posted December 3, 2014 Author Share Posted December 3, 2014 I did a counter at the FOR because there is one to let the WHILE work. So both has something to do the same fair play Link to comment Share on other sites More sharing options...
Luigi Posted December 3, 2014 Share Posted December 3, 2014 (edited) may I suggest >this and >this. Edited December 3, 2014 by Detefon Visit my repository Link to comment Share on other sites More sharing options...
Spider001 Posted December 3, 2014 Author Share Posted December 3, 2014 that's a good one Detefon '?do=embed' frameborder='0' data-embedContent>> thanks for this one Link to comment Share on other sites More sharing options...
BrewManNH Posted December 3, 2014 Share Posted December 3, 2014 Just as an FYI for the next time you, or anyone else, has such a simplistic question I'd like to suggest to you to try it before asking. It would have taken FAR less time to test the two methods with a timerinit/timerdiff, than it took to find the answer here. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Spider001 Posted December 3, 2014 Author Share Posted December 3, 2014 Just as an FYI for the next time you, or anyone else, has such a simplistic question I'd like to suggest to you to try it before asking. It would have taken FAR less time to test the two methods with a timerinit/timerdiff, than it took to find the answer here. That coding whas faster then finding the link else i maybe not code that or maybe i did even whit that link . why make so big problem of it. Link to comment Share on other sites More sharing options...
BrewManNH Posted December 3, 2014 Share Posted December 3, 2014 Why ask a question instead of running the code and timing it yourself? Did you really need to ask the question in the first place is all I'm getting at. It's not a big problem, it's just you asking a stupid question that really didn't need to be asked. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now