Jump to content
Sign in to follow this  
Spider001

speed

Recommended Posts

Spider001

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 by Spider001

Share this post


Link to post
Share on other sites
mikell

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)

Share this post


Link to post
Share on other sites
Spider001

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 by Spider001

Share this post


Link to post
Share on other sites
Spider001

 

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 by Spider001

Share this post


Link to post
Share on other sites
Spider001

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 :)

Share this post


Link to post
Share on other sites
Luigi

may I suggest >this and >this.

Edited by Detefon

Visit my repository

Share this post


Link to post
Share on other sites
BrewManNH

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 Gude
How 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

Share this post


Link to post
Share on other sites
Spider001

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.

Share this post


Link to post
Share on other sites
BrewManNH

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 Gude
How 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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×