Re: For vs. For Each

From: Cablewizard (Cablewizard_at_Yahoo.com)
Date: 08/12/04


Date: Thu, 12 Aug 2004 10:14:17 -0600

I gave this a little bit of thought. I realized that the sort of coding I do is
quite different than what "most" people are doing. I perform mostly engineering
and geospatial analysis. For me, this involves many loops, and loops within
loops. Along with iterating over recordsets countless times. In a literal since,
this is data processing in the extreme, but certainly not like manual data
entry.

However, loops are used to perform some sort of search and/or work on a block of
items. By nature, they can consume a decent portion of the overall processing
time as they are oftentimes the place where much of the actual work is taking
place. Any number of smaller functions may be performed, but potentially it is
performed many if not thousands of times. In this particular thread's example,
the operator is iterating through all the controls in a collection, presumably
to do something with them. I would hazard a guess that if you compared the
overall processor time spent within the scope of the loop, it would be
significant relative to other non-loop functions.

So while what I do may in fact be much different than most others, I still stand
by my statement. Just look at the number of times people want to know how to
keep their GUI responsive while some sort of iterative process is occurring.
Forget for a moment about the design considerations of what is really happening.
Bottom line is that the iterative processing is consuming an amount of time
significant enough to be noticeable to the operator.

Since you asked, and to exemplify Alvin's comments, here is a common occurrence
for me.
(For those who don't what to read a confusing and long-winded example, stop
reading here)
I have a geospatial dataset that contains some number of polygons/regions.
I need to find any overlapping/intersecting regions and degenerate those
intersections into separate regions.
This requires iterating through every element in the dataset and compare it to
every other element.
Additionally, for every potentially intersecting element combination, you must
iterate through every combination of vertices/segments to determine
intersection.
Each combination of intersections could result in the creation of a new region.
Each new region could also intersect with subsequent existing and/or new
regions, which could also generate new regions...
Now, if when existing regions could be degenerated into sub-regions, I could
remove the existing regions from the collection and add the new regions to the
end of the collection, then theoretically I could determine all possible tests
within the scope of 1 top-level For Each loop. But instead, I must be creative
and do something like mark the existing regions for deletion within the master
collection, add the newly created regions to a separate collection. Then perform
the same iteration over the new collection, and potentially create an additional
collection, and so on. Once all combinations are resolved, then I must go back
and iterate through all of the resulting collections to recreate the master
collection. Now in practice, the resulting implementation isn't exactly like
that, but logically it is similar.

So for me, loop performance and implementation is extremely important.

Gerald

"Cor Ligthert" <notfirstname@planet.nl> wrote in message
news:eijj0FGgEHA.4092@TK2MSFTNGP10.phx.gbl...
> Can you give some sample applications where this statement of you is true?
>
> > Although due to the nature of loops, they oftentimes fall into
> > the 20 percent of code that consumes 80 percent of the time.
>
> It is in my opinion definitly not with applications where is by instance
> screen painting or/and dataprocessing.
>
> It is in my opinion definitly true for applications where is image
> processing where not the GDI+ encoding is used.
>
> However that is in my opinion surely not the majority of the applications.
>
> So I am curious in what type of other applications stand alone loops can
> consume 80% of the time?
>
> Just my thought,
>
> Cor
>
>



Relevant Pages

  • Re: For vs. For Each
    ... For me, this involves many loops, and loops within ... Along with iterating over recordsets countless times. ... Each combination of intersections could result in the creation of a new region. ... > Can you give some sample applications where this statement of you is true? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: For vs. For Each
    ... For me, this involves many loops, and loops within ... Along with iterating over recordsets countless times. ... Each combination of intersections could result in the creation of a new region. ... > Can you give some sample applications where this statement of you is true? ...
    (microsoft.public.dotnet.general)
  • Re: For vs. For Each
    ... For me, this involves many loops, and loops within ... Along with iterating over recordsets countless times. ... Each combination of intersections could result in the creation of a new region. ... > Can you give some sample applications where this statement of you is true? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: For vs. For Each
    ... think that the code which is created by the ILS will make a lot of loops. ... Looping is in my opinion the basic of good programming, ... Along with iterating over recordsets countless times. ... >> It is in my opinion definitly not with applications where is by instance ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: For vs. For Each
    ... think that the code which is created by the ILS will make a lot of loops. ... Looping is in my opinion the basic of good programming, ... Along with iterating over recordsets countless times. ... >> It is in my opinion definitly not with applications where is by instance ...
    (microsoft.public.dotnet.languages.vb)

Quantcast