Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Efficencieny of Loops 5

Status
Not open for further replies.

Zarcom

Programmer
May 7, 2002
1,275
CA
I got the idea to test out how fast different loop structures in VB are from thread796-425375. I Tested the if elseif contruct against the select case construct.

I looped through a form with 8 different controls on it 10,000 times and ran it thru each construct respectively.
I did 20 sets of this and 3 trials The totals that I got are. The numbers are measured in clock ticks

Total
Select Case/For Each: 6549479
Select Case/For Next: 6460937.6
If ElseIf/For Each: 14929687.6
If ElseIf/For Next: 18744791.3

Select Case is 2.59 X faster than if ElseIf

I also decided to run a For Each against a For Next.
This I ran 1,000,000 times. Once again with 20 sets and 3 trials. The totals that I got are. The numbers are measured in clock ticks.

Total
For Each: 16283854.6
For Next: 4653645.3

For Next is 3.50 X faster than For Each


For the results I got you can see that it is benificial to use Selects and For Next statments whenever possible. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
nice research Mark, thanks for the input! Daren J. Lahey
Just another computer guy...
FAQ183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
Support your forums TODAY!
 
that's awesome. Thanks Mark!
 
Good Stuff, Zarcom.
penny1.gif
penny1.gif
 
thanks guys!
hee hee nice star sthmpsn That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
whoops. ;-)
penny1.gif
penny1.gif
 
Kick ass post Mark.

You're now nominated as this forum's tester-outer guy.

Could you tell me how fast translating the MSDN site to Yiddish would be if we use an access database, a dataset, and only 2 coders?
;)

Star for you (hey, SOMEONE in Edmonton needs to get points, righ Esky-boy?)
;)

D
 
[rofl2]
Well I would need a little more info then Jack. Which dialect of Yiddish did you want? Also do you want total project time including building of the translation software or simple the time it takes to translate?

I wouldn't say to much about our Eskimo's I do believe we beat you which makes your people a step behind ya? ;)

Thanks That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Total
For Each: 16283854.6
For Next: 4653645.3

Question...
Code:
For Each [i]item[/i] In [i]collection[/i]
...
Next

Isn't that a For Next statement? What's the difference between For Each and For Next?

(Figure's them Canadians would know it faster than us RedNeck Yokels.)
 
Its like this:

For Each Bottle in Cellar
Me.Drink(Bottle)
Next

For BottleCount <> 0
Me.Drink(Cellar.Bottles(BottleCount))
Next

you'd probably use them differently (i.e. if you wanted to inspect each bottle before drinking, you'd use for each. If you just wanted to get drunk fast, you'd just keep going until none were left.

I think what Mark was showing is that if given the choice, you should use for next. But sometimes a for each is the only option.

D'Arcy

ps: Losing the Grey Cup AT HOME, on your HOME FIELD is alot worse than losing on the road. ;)
 
Wouldn't a While routine be more gramatically correct?

(Long time no see BTW.)
 
grammatically correct? We are programmers we just use whatever works.

Maybe I'll run a while through my tests see what that gets.

for i=0 to Cellar.Count
...
Next

uses an integer which has been efficientized

for each Bottle in Cellar.Bottles
...
Next
uses an object, Bottle is set to the next bottle in every loop That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
efficientized... you guys and your big words. I get how those worked, I just never distinguished between the two. D'Arcy's example tho, really looked like it should have said:
While BottleCount > 0
Me.Drink(Cellar.Bottles(BottleCount))
End While

But I guess they both work. And I guess I never have met a programmer with good grammer skills. It's hard to worry about grammer when you're about to beat your best Minesweeper score... ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top