Re: The inaugural VB6 vs dot net test
- From: Ulrich Korndoerfer <ulrich_wants_nospam@xxxxxxxxxxxx>
- Date: Sun, 02 Dec 2007 22:38:14 +0100
Mike Williams wrote:
"Ulrich Korndoerfer" <ulrich_wants_nospam@xxxxxxxxxxxx> wrote in message news:OY10nF8MIHA.5040@xxxxxxxxxxxxxxxxxxxxxxx
. . . and changed the loop direction in Invert1 back to
counting from 0 up. Counting down actually is slower.
Yep. That's why I counted up in my own code. In this particular case counting down means you are addressing the bitmap memory in a "top down" fashion as well, which kind of "goes against the grain" of the memory cache, hence slowing the code down.
In my oppinion the reason why one could hope that counting down to 0 makes loops running faster comes from how the compiler handles those loops. Some time ago I had a look at the assembler code the compiler generates for counting up loops. As far as I remember, the final value (the loop stops when the loop counter exceeds this value) is stored in a local variable on the stack. On each iteration this final value is loaded back from the stack into a CPU register and then compared with the loop counter. If however a loop counts down, the final value is zero, and so the compiler theoretically could optimize this by just comparing against zero. It would not be necessary to load the final value for each iteration, so the loop should execute a litle bit faster. I hadn't a look on the assembler code generated for this case, but as the counting down loop is not faster, I assume the compiler still loads a value from the stack (being zero), not doing the optimization it could do here.
Now both methods are equally fast. Invert3 respects padding
bits, but is optimized for 24bpp, Invert1 is more general
regarding the bpp, but changes padding bits.
// New test results
Compiled to native code, settings are:
"Compile for speed, use *all* extended optimizations"
Intel Core 2 Duo @ 1.86 GHz
1024 x 768 bitmap, 24 bits per pixel
1001 iterations per run, 3 runs
Invert1: 1.504, 1.508, 1.505 sec
Invert3: 1.503, 1.502, 1.504 sec
I'm getting 5.512, 5.461, 5.495 on my own AMD Athlon 3000+ (2.2 Ghz) machine, which just a bit faster than the 6.133, 6.156, 6.166 that I'm getting with my own code. There isn't much of a difference, and I expect it might be because all my code is in the Form whereas your main code is in a module, which might make a bit of difference. Might try using a module for my own code later to see if it makes a difference. Not that it really matters of course, because the speeds are pretty much the same anyway.
Which code did you use? The one you posted (using a two dimensional array and two nested loops) or a version that uses a 'flat' (1 dim) array? Using a two dimensional array implies for each access more adress calculating work: two multiplications (multiplying the column index with the element length and multiplying the row index with the row length) and two additions. Where a 1 dimensional array only needs one multiplication and one addition.
What /is/ interesting though is how much faster your Core 2 Duo 1.86 Ghz runs. I've been putting off getting a new machine for a long time now, thinking that they are not yet fast enough to warrant the change, but having seen your figures I think I'm going to get one pretty soon :-) If one core runs so much faster than my own machine then it should fairly fly when running stuff optimized for two cores. Or maybe I'll wait for the 256 core machines to appear ;-)
Since using the 'core' or 'core2' architecture, Intel processors seem to be faster than the AMD ones. The older architectures Intel used however were slower than the AMD ones.
--
Ulrich Korndoerfer
VB tips, helpers, solutions -> http://www.proSource.de/Downloads/
.
- Follow-Ups:
- Re: The inaugural VB6 vs dot net test
- From: Mike Williams
- Re: The inaugural VB6 vs dot net test
- References:
- Re: The inaugural VB6 vs dot net test
- From: Ulrich Korndoerfer
- Re: The inaugural VB6 vs dot net test
- From: Ulrich Korndoerfer
- Re: The inaugural VB6 vs dot net test
- From: Mike Williams
- Re: The inaugural VB6 vs dot net test
- Prev by Date: Re: VB6 versus VBNet Challenge
- Next by Date: Re: alternative to gettickcount
- Previous by thread: Re: The inaugural VB6 vs dot net test
- Next by thread: Re: The inaugural VB6 vs dot net test
- Index(es):
Relevant Pages
|
Loading