![]() |
| | #1 |
| Registered User Join Date: Oct 2008
Posts: 85
| Speed comparison This is working on the premise that there are no watch points or break points active and i am just checking through the running state. Should this be a concern on a small test project ? i am continually improving my code as i go, as and when i establish better ways to achieve the same goal. but does this :- Code: int x;
int y;
x= 50;
y= 50;
for (x=0;x<10;x++)
{
for (y=0;y<10;y++)
{
//dosomething here
}
}
Code: for(int x=0;x<10;x++)
{
for(int y=0;y<10;y++)
{
//do something here
}
}
thanks |
| deviousdexter is offline | |
| | #2 |
| Banned Join Date: Aug 2001 Location: Visalia, CA, USA
Posts: 3,699
| Nope. |
| master5001 is offline | |
| | #3 |
| Registered User Join Date: Aug 2008
Posts: 188
| don't worry about this stuff. the compiler will optimize it most of the time for you anyways. but assuming no optimizations, the 1st version is slower because x,y are declared to 0 (for C#, not C++), and then it's set to 50, and then it's set to 0 again. the 2nd version it gets set once. |
| bling is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to sort a simple linked list using swap-sort method | JOCAAN | C Programming | 24 | 08-07-2009 11:48 AM |
| I am very new . . . :( | Eternalglory47 | C++ Programming | 6 | 09-05-2008 11:29 AM |
| Speed comparison between vector and 2*2 array | cunnus88 | C++ Programming | 5 | 11-25-2007 02:05 AM |
| Flight Simulator Wind Speed!! | Dilmerv | C++ Programming | 6 | 03-20-2006 12:40 AM |
| C/C++ vs assembly: speed comparison | Just | C++ Programming | 11 | 11-25-2002 03:33 PM |