Re: Poor array performance

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Ouch. I should have looked closer at the code and tested the results before
posting. That would have avoided some confusion. Thanks for setting me
straight on what was actually happening. After I fixed my code here, you
are correct, I'm getting equivalent speed to the C# code.


"Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx> wrote in message
news:erF83LZLGHA.3960@xxxxxxxxxxxxxxxxxxxxxxx
No I mean that the C++ figures are wrong because of "broken" optimization.
If I run the code (managed C++) you posted it takes 0.210 secs. to
complete,
impressive, but I don't trust it.
Now if I watch the memory consumption when running (1000 iterations to
make
it possible to measure), the "private bytes" counter stays at ~9 Mb and
the
working-set at ~6.5 Mb, wich is the minimum for a ".NET" process, this
smells like agressive optimization. Why?, well the program should create
two
arrays of doubles (well, the optimizer could optimize away the first
array),
each of them - 8784*1000*sizeof(double) = 70.272.000 bytes. That means
that
the final private bytes count should reach at least 70.272.000 (or
140.544.000 bytes).
So it's clear that NO arrays are created, that would mean both array
creation are optimized away (which is possible because they aren't used
outside the loop, right?
So I decided to look at the results, by including this code after the
loop:

for (Hourly_Index = 0; Hourly_Index < 1; Hourly_Index++)
{
for (Iteration_Index = 0;Iteration_Index < 1000 ; Iteration_Index++ )
{
Console::WriteLine("{0}", Convert::ToString(vombase[Iteration_Index,
Hourly_Index]));
}
}
See, I'm only interested at the first 1000 elements, and he! they are all
at
0, thus wrong! The I watched the last elements values, they are all at
998001, which is 999^2 or the largest value calculated in the loop. Finaly
I
checked all the 'values' and guess, there are only 0 (the first 1.000.000)
and 998001 (the remaining), but still no array's, the memory consumption
remain the same.
So, this is what I call "broken optimization", the results are wrong, so
the
benchmarh time is bogus.

Note that I did the same with the C# code, and here the results are
correct,
memory consumption is > 140Mb and the benchmark time is correct (5.2 Secs.
on my box).

Actually I didn't look into the generated code, I will do is I find some
spare time.

Willy.


.



Relevant Pages

  • Re: Use of ANY
    ... If the condition "almost always" occurs, then a DO loop with a short circuit exit on the first ... compiler will generate efficient code (unrolling, pipelined execution, ... loops through the whole array to implement ANY. ... I assume that any compiler run with a modest optimization level ...
    (comp.lang.fortran)
  • Re: Data Structure Speed
    ... Eric Sosman wrote: ... N - 1 (where N is the size of the array), I need to update the same ... Knuth wrote that "Premature optimization is the root of ... Oops, sorry for the top-post. ...
    (comp.lang.java.help)
  • RE: Error 3021
    ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)
  • RE: Error 3021
    ... Kevin Backmann ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)
  • RE: Error 3021
    ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)