Re: RES: [Dev-C++] Optimizing C code, what is best??
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-05-31 11:33:02
|
The order used shouldn't matter because of the large loop count. After the first iteration, the loop and data will be cached. Any noise you see in the numbers are just round-off errors and background noise in your machine. However, you should not use a 64-bit loop counter unless you compile for an Opteron, Itanium or similar 64-bit processor. 32-bit unsigned handles 4 billion iterations which should be enough. What compile optimization did you use? Did you inline the code or not? If not inlined, I would expect the actual call to take up a significant amount of time, completely masking any optimiazation of the dist-sqr loop. In this case, the code was critical, since the original program was consuming 50% of the time performing dist-sqr evaluation. /Per W On Sat, 31 May 2003, Graeme Foster wrote: > Greetings, > > I ran the code you posted and my results were certainly not as impressive as > yours. > > start (C++) > 1 (37) 186 > 2 (35) 186 > 3 (32) 186 > 4 (33) 186 > > start (C++ reverse order) > 4 (33) 186 > 3 (32) 186 > 2 (35) 186 > 1 (36) 186 > > start (C reverse order) > 4 (33) 186 > 3 (32) 186 > 2 (35) 186 > 1 (36) 186 > > I made a few changes - not to the methods but to main where I added a system > pause and declared a loop counter so I could change the value. I ran with > the following: DWORD64 loop = 100000000; > > Yes their is a difference but marginal. That difference is important if the > code is time critical otherwise it probably doesn't really matter. More > importantly is the algorithm, I could rewrite the code to be horrible > inefficient (nest a for loop and then replacing the iA*iA with iA+iA). > > Graeme. > > > > ------------------------------------------------------- > This SF.net email is sponsored by: eBay > Get office equipment for less on eBay! > http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |