Author |
Message |
|
jtchange
Newbie
Joined: 20 Dec 2003 Posts: 27
|
Posted: 19 Feb 2004 12:28:39 pm Post subject: |
|
|
Which is faster? I've heard that For loops are essentially faster, but it miust only be slightly faster because i cannot tell. What do you think? |
|
Back to top |
|
|
Darth Android DragonOS Dev Team
Bandwidth Hog
Joined: 31 May 2003 Posts: 2104
|
Posted: 19 Feb 2004 12:54:43 pm Post subject: |
|
|
not sure, test this progie:
Code: For(A,1,1000
End
Pause
While A>1
A-1->A
End
it loops the for loop 1000 times then loops the while loop 1000 times. time it to see which is faster
a for loop translates like this:
For(variable,begin,end,increment
End
becomes
begin->variable
While variable<end
variable+increment->variable
End
variable+increment->variable
the extra variable+increment->variable on the end is used in the for loop for double checking that it reached the end or whatever, you probably wouldnt use it if you decided to use a while loop. i tried to make inputs out puts the same, not optimize.
i personally think that a for loop is faster than a while loop, because a for loop has its own command in asm, djnz.
Last edited by Guest on 19 Feb 2004 12:55:32 pm; edited 1 time in total |
|
Back to top |
|
|
jtchange
Newbie
Joined: 20 Dec 2003 Posts: 27
|
Posted: 19 Feb 2004 05:17:05 pm Post subject: |
|
|
ok here are the results:
For loop: 55 seconds
While loop: 1 minute and 5 seconds
that solves it! For( loops are faster and you should use them in ur programs rather than while loops.
Anything else someone wants me to test for spped?? |
|
Back to top |
|
|
X1011 10100111001
Active Member
Joined: 14 Nov 2003 Posts: 657
|
Posted: 19 Feb 2004 05:30:12 pm Post subject: |
|
|
I think while loops are faster if you're not increaseing/decreasing a variable. |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 19 Feb 2004 05:44:27 pm Post subject: |
|
|
Check this:
Code: For(X,1,1000,2
End
Code: 1->X
While X <= 1000
X+2 -> X
End
For the 1-increment, also try Code: 1 -> X
While 1
IS>(X,1000
End which might be faster.
Last edited by Guest on 19 Feb 2004 05:44:39 pm; edited 1 time in total |
|
Back to top |
|
|
Darth Android DragonOS Dev Team
Bandwidth Hog
Joined: 31 May 2003 Posts: 2104
|
Posted: 19 Feb 2004 05:48:59 pm Post subject: |
|
|
good point.
well, try that omni. |
|
Back to top |
|
|
Jedd 1980 Pong World Champion
Elite
Joined: 18 Nov 2003 Posts: 823
|
Posted: 19 Feb 2004 05:54:19 pm Post subject: |
|
|
Has anyone seen my last post on the Chip's Challenge topic? I explained the project I wanted to do after CC is done. It's going to be a complete list of how long everything is in BASIC, what's faster than what, how long one command takes compared to another, that kind of thing. Maybe jtchange and some other people should start working on something like that. |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 19 Feb 2004 05:54:20 pm Post subject: |
|
|
What about For( loops with a negative increment? They might be slower.
Edit: I think I heard somewhere that Fors with closed parentheses are faster. Tell me that's not true.
Last edited by Guest on 19 Feb 2004 05:55:02 pm; edited 1 time in total |
|
Back to top |
|
|
Jedd 1980 Pong World Champion
Elite
Joined: 18 Nov 2003 Posts: 823
|
Posted: 19 Feb 2004 06:03:16 pm Post subject: |
|
|
Nope, it's not true.
For(A,1,10000
End
24 Seconds
For(A,1,10000)
End
27 Seconds |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 19 Feb 2004 06:10:37 pm Post subject: |
|
|
Thank you. You have just saved me from un-optimising all of my programs |
|
Back to top |
|
|
jtchange
Newbie
Joined: 20 Dec 2003 Posts: 27
|
Posted: 19 Feb 2004 07:36:58 pm Post subject: |
|
|
yeah i checked out the difference in size too, the while loop is a bit smaller than the for loop(depends on the numbers in the for loop) but that's where you make the choice; size or speed? for game programmers, i would think speed and for 'programmers' who make programs that people utilize might want to save space. it all depends on ur perspective on what is more important
I would not mind at all if anyone wanted me to test things for speed to see which is faster. I could record these things on a website. people can send me codes and i will test to see which variation of certain codes are faster than the other. you can find me on AIM at jtchange22 or on msn jt_change22@msn.com
-jt |
|
Back to top |
|
|
Darth Android DragonOS Dev Team
Bandwidth Hog
Joined: 31 May 2003 Posts: 2104
|
Posted: 20 Feb 2004 01:57:20 am Post subject: |
|
|
1) why do you have the same avatar as omni?
2) well, a For( loop is a specialized While loop, it should be faster.
3) test this (strings versus lists):
Code: For(A,1,1000
B->L1(1
L1(1->B
End
Pause
For(A,1,1000
Str1->Str2
Str2->Str1
End
4) and this (the 6 special lists versus named lists):
Code: For(A,1,1000
B->L1(1
L1(1->B
End
Pause
For(A,1,1000
B->LTEST(1
LTEST(1->B
End
Last edited by Guest on 20 Feb 2004 01:59:14 am; edited 1 time in total |
|
Back to top |
|
|
Adm.Wiggin aka Tianon
Know-It-All
Joined: 02 Jun 2003 Posts: 1874
|
Posted: 20 Feb 2004 05:43:14 pm Post subject: |
|
|
4 letter named lists no less |
|
Back to top |
|
|
Darth Android DragonOS Dev Team
Bandwidth Hog
Joined: 31 May 2003 Posts: 2104
|
Posted: 20 Feb 2004 07:12:44 pm Post subject: |
|
|
well, the named lists have to be checked for, data loc, etc. the standard ones are built in, so i though that they may be faster... |
|
Back to top |
|
|
Arcane Wizard `semi-hippie`
Super Elite (Last Title)
Joined: 02 Jun 2003 Posts: 8993
|
Posted: 21 Feb 2004 02:34:53 am Post subject: |
|
|
I'm quite sure they are. |
|
Back to top |
|
|
Adm.Wiggin aka Tianon
Know-It-All
Joined: 02 Jun 2003 Posts: 1874
|
Posted: 21 Feb 2004 01:29:00 pm Post subject: |
|
|
i was commenting on the length of the name... of course, a 4 letter name will take longer than a 1 letter name, and a prenamed list should be fastest... a 4 letter name will take longer than a 1 letter name because the parser has to check more text... (thus taking longer) |
|
Back to top |
|
|
MaxVT103
Member
Joined: 24 Aug 2003 Posts: 109
|
Posted: 21 Feb 2004 01:47:04 pm Post subject: |
|
|
Well think about it thisway, a For loop should always be faster than a while loop because it takes the memory it needs and stored its max and min value so it knows where its going. A while loop has to go into memory and usualy check a variable to see if it is equal to and such like. But the advantage of a while loop is you can use it as a for loop but it doesn't work very well vise versa. |
|
Back to top |
|
|
X1011 10100111001
Active Member
Joined: 14 Nov 2003 Posts: 657
|
Posted: 21 Feb 2004 04:26:58 pm Post subject: |
|
|
Darth Android wrote: 3) test this (strings versus lists):
Code: For(A,1,1000
B->L1(1
L1(1->B
End
Pause
For(A,1,1000
Str1->Str2
Str2->Str1
End
if you wanted to make that a fair test, you should do something like this:
Code: For(A,1,1000
L1->L2
L2->L1
End
Pause
For(A,1,1000
Str1->Str2
Str2->Str1
End
|
|
Back to top |
|
|
|