Re: how much does array size affect compiling speed?
thanks again for the suggestion!!! Heres the current code. I think the problem may be solved! I was able to get 500 n_simulations in only 5 minutes, which is about 10 times the previous speed. I'll now include the rest of the program that I didn't include earlier and see if it still works
Last edited by larry burns; November 21st, 2009 at 04:16 PM.
Re: how much does array size affect compiling speed?
You still have a few
Code:
{
int t = 1;
}
left in your code. I thought you said that you've fixed it...
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinWindows - replacement windows manager for Visual Studio, and more...
Re: how much does array size affect compiling speed?
Few more comments?
Your code has a LOT of levels of nestedness (is that a word?), so whatever you can do to reduce it – please do.
Your statement:
Code:
if( n_simulations != 0 )
is right after n_simulations is initialized with 1 – just remove it.
I should have stated earlier – never EVER modify loop counter inside the loop (other then for regular step). You are making it impossible to read your code.
Code:
for ( double f = 0; f < 1; f = f + .004 )
{
if( (x_value) < f + .004 && (x_value) >= f )
{
x = -(n_size - (2 * n_size * f) - 1);
f = 1;
}
}
is the same as
Code:
for ( double f = 0; f < 1; f = f + .004 )
{
if( (x_value) < f + .004 && (x_value) >= f )
{
x = -(n_size - (2 * n_size * f) - 1);
break;
}
}
without forcing a reader to follow the usage of variable f to see why it needs to be set to 1.
Now look at this loop:
Code:
for ( int j = 1; j < 500; j++ )
{
for ( int e = 0; e < 250; e++ )
{
for ( int f = 0; f < 250; f++ )
{
if( island[e][f] == j )
{
IslandSize[j - 1]++;
}
}
}
}
What do you need the outer loop for? You are running through you 250*250 matrix (it’s already 62,500 iterations) 500 times, without changing anything!
Isn’t it pretty much the same as:
Code:
for ( int e = 0; e < 250; e++ )
{
for ( int f = 0; f < 250; f++ )
{
IslandSize[island[e][f] - 1]++;
}
}
only 500 times slower?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinWindows - replacement windows manager for Visual Studio, and more...
Re: how much does array size affect compiling speed?
In addition, this loop is indeterminate as to how many times it will execute:
Code:
for ( double f = 0; f < 1; f = f + .004 )
Never, never, never use doubles as loop counters!
The reason is that doubles are not exact. When you add 0.004, there is round-off error involved, since 0.004 cannot be represented exactly as a binary floating point number. So when you add 0.004, the value of f is not exact.
Now, how many times will the loop run? You don't know due to the round-off error.
Always use integers for loop counters. The loop should be rewritten:
Code:
double f;
for (int fInt = 0; fInt < 1000; fInt += 4)
{
f = (double)fInt / 1000.0;
// now do your calculations using f
//...
}
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.