CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 19

Threaded View

  1. #8
    Join Date
    Nov 2009
    Posts
    27

    Re: how much does array size affect compiling speed?

    Quote Originally Posted by VladimirF View Post
    However, this makes NO SENSE at all:
    Code:
    {int t=1;}
    You define a local variable t that goes out of scope right away. (This happens more than once in your code).



    Now one thing about efficiency. You have this nested loop (a few times):
    Code:
    for (int a=0; a<250; a++)
    {    
    	for (int b=0; b<250; b++)
    	{ 
    		if (island[125-y][x+124]>island[a][b])
    		{t=0;}
    
    	}
    }
    Note that inner part is executed 62,500 times.
    Note also that after the very first time you set t to 0, the rest of those loops can’t possibly make any difference. See if you can break out of there.

    This whole thing is triple-nested into
    Code:
    for(int i=0;i<n_walks;i++)// 'FOR' STATEMENT IS A TYPE OF LOOP
    {
    	for (int f=125; f>-116; f=f-10)
    	{
    		for (int g=125; g>-116; g=g-10)
    		{
    which produces 500,000 * 25 * 25 = 312,500,000 iterations of the previous fragment. No wonder it takes long time!

    Could you please clean up you code and repost here for further analysis?
    what do you mean the t=1 goes out of scope right away? I need it there so it can run through the if(t!=0) part

    Thanks alot for that suggestion to break out of the loop after setting t to 0. My program now runs faster, but its still ridiculously slow. It would now take 23 hours or so to run 11,250 n_simulations

    how can I clean up the code? Sorry for the mess, but isn't it easier to read if I skip a line for the 'for' statements?
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured