Jump to content

Execution Speed

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
atrip25

atrip25

    Newbie

  • Members
  • PipPip
  • 26 posts
initializing an array in C++, which of these two will give me faster execution time?
double A[100][100];
    ...
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            A[i][j] = i * j;
        }
     }
double A[100][100];
    ...
    for (int j = 0; j < 100; j++) {
        for (int i = 0; i < 100; i++) {
            A[i][j] = i * j;
        }
     }

Edited by Jordan, 20 October 2009 - 10:32 AM.
pleas use code tags!


#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Why would their be any difference in speed? You've only given the number a different variable name.

I've added code tags. Please use them when posting code.

#3
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Shouldn't this be in the C/C++ forums, not the C# forums?

Anyway, I actually see what he's asking, and it has to do with how he's accessing the arrays, Jordan. :) As far as I know, there's no performance difference either way with accessing arrays, in C and C++ arrays are nothing more than a block of contiguous memory, and by whichever offset values you apply and in whatever order will still result in the same execution speeds. I may, however, be wrong, and hopefully someone more knowledgeable on array access will show up.
Wow I changed my sig!

#4
atrip25

atrip25

    Newbie

  • Members
  • PipPip
  • 26 posts
I wouldn't think there would be a performance difference myself. It was a question someone asked me and thought I would post. My initial response was the same as Jordan's.

#5
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Is this a C# or C++ question?

#6
warden26

warden26

    Newbie

  • Members
  • PipPip
  • 26 posts
Don't you worry about speed when doing such a fundamental operations. It really doesn't matter now, and you can test both codes to see that the execution time is the same.

Edited by warden26, 31 August 2010 - 05:32 AM.

It's the worlds hardest game, what can I say more?

http://www.worlds-hardest-game.com