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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Iterating?

Status
Not open for further replies.

vladibo

Programmer
Sep 14, 2003
161
CA
Is iterating of Enumerator more efficient than the iterating with for loop?

Thanks in advance
 
What do you mean by "Is iterating of Enumerator"? An enum is just an int.

When iterating in a for-loop you can iterate in a kazzilion ways...it depends on the iterator. ++ on an int is just one (but fairly efficient) way.

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
Sorry, I meant the enumerator from System::Collections::ArrayList::GetEnumerator()
 
The best way to see that, is testing of both situations.

Ion Filipski
1c.bmp
 
Since a simple for-loop counting to zero using an integer should compile on any reasonable compiler to something like
mov thingy, count
start-of-loop:
whatever code you want
dec thingy
jnz start-of-loop
where "thingy" is either a global variable in ds or a local variable in ss (doesn't matter which, they're both equally efficient to access), it's hard to think how you can make something substantially more efficient than this.
The only obvious improvement is to keep the loop counter in a register, but your compiler will probably have done this for you already if it is more efficient. It might not be, if the loss of a register for other purposes causes problems. I gather some compilers even have the sense to convert a count-up loop to a count-down loop if the loop variable isn't used elsewhere.

 
As I see there is something about an ArrayList. It is a .NET class. For that reason, the best way to iterate in my opinion is using of the API provided by that class.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top