Click here to Skip to main content
15,891,940 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionThere is a better way to achieve that? Pin
Stephan Poirier20-Feb-05 19:25
Stephan Poirier20-Feb-05 19:25 
AnswerRe: There is a better way to achieve that? Pin
22491720-Feb-05 23:10
22491720-Feb-05 23:10 
AnswerRe: There is a better way to achieve that? Pin
V.21-Feb-05 0:34
professionalV.21-Feb-05 0:34 
GeneralRe: There is a better way to achieve that? Pin
22491721-Feb-05 0:37
22491721-Feb-05 0:37 
GeneralRe: There is a better way to achieve that? Pin
V.21-Feb-05 4:35
professionalV.21-Feb-05 4:35 
AnswerRe: There is a better way to achieve that? Pin
Zdeslav Vojkovic21-Feb-05 5:58
Zdeslav Vojkovic21-Feb-05 5:58 
GeneralRe: There is a better way to achieve that? Pin
22491721-Feb-05 16:35
22491721-Feb-05 16:35 
GeneralRe: There is a better way to achieve that? Pin
Stephan Poirier21-Feb-05 19:57
Stephan Poirier21-Feb-05 19:57 
That's what I thought at first sight. I didn't tested Zdeslav's code, I just relied on the comment he gaves us, it seemed to have sence. I didn't thought to scan the code in assemblySniff | :^) , my faultSmile | :) !

So I did a little test with performance counters, just to see what's the real result... Big Grin | :-D

I tested the code on my old P3 450, I've tested each solution 10 times and did an average.

For the Zdeslav solution:
 <code>void UltraSwap( LONG* a, LONG* b )
{
   LONG t = *b;
   *b = *a;
   *a = t;
}</code> 

                     IN DEBUG                   IN RELEASE
One single call   : 0.004190476 ms              0.004190476 ms
1000 calls loop   : 0.186895210 ms              0.035199995 ms
10000 calls loop  : 1.822018770 ms              0.307580906 ms


and for the suhredayan solution:
 <code>_inline PVOID UltraSwap2( LONG* a, LONG* b )
{
    __asm mov eax, dword ptr [a]
   __asm mov ebx, dword ptr [b]
   __asm mov dword ptr [a], ebx
   __asm mov dword ptr [b], eax
}</code> 

                     IN DEBUG                   IN RELEASE
One single call   : 0.004190476 ms              0.003352380 ms
1000 calls loop   : 0.170133307 ms              0.016761902 ms
10000 calls loop  : 1.599923566 ms              0.158399976 ms

So, know, everyone can see the results. I don't think I have to explain furter... Big Grin | :-D
In debug mode, there is not a lot of difference but after a 10000 calls loop in release mode, now I'm sure that UltraSwap2 is the great winner! It just took the half time of the other one.

If you want to see my test code, let me know, I will try to post it.

Thanks suhredayan for your advise, you pointed me on the right track!!

Have a nice day,
Stef

Progamming looks like taking drugs...
I think I did an overdose. Poke tongue | ;-P
GeneralRe: There is a better way to achieve that? Pin
Zdeslav Vojkovic22-Feb-05 0:36
Zdeslav Vojkovic22-Feb-05 0:36 
GeneralRe: There is a better way to achieve that? Pin
Stephan Poirier21-Feb-05 21:00
Stephan Poirier21-Feb-05 21:00 
GeneralRe: There is a better way to achieve that? Pin
Zdeslav Vojkovic22-Feb-05 2:27
Zdeslav Vojkovic22-Feb-05 2:27 
GeneralRe: There is a better way to achieve that? Pin
Stephan Poirier22-Feb-05 14:47
Stephan Poirier22-Feb-05 14:47 
GeneralRe: There is a better way to achieve that? Pin
Stephan Poirier22-Feb-05 14:56
Stephan Poirier22-Feb-05 14:56 
AnswerRe: There is a better way to achieve that? Pin
Stephan Poirier21-Feb-05 16:18
Stephan Poirier21-Feb-05 16:18 
Questionhow to achieve a secure file system against information leak? Pin
zymoonstone20-Feb-05 19:12
zymoonstone20-Feb-05 19:12 
AnswerRe: how to achieve a secure file system against information leak? Pin
22491721-Feb-05 0:45
22491721-Feb-05 0:45 
GeneralRe: how to achieve a secure file system against information leak? Pin
zymoonstone21-Feb-05 13:54
zymoonstone21-Feb-05 13:54 
QuestionConnected or not? Pin
wasife20-Feb-05 18:58
wasife20-Feb-05 18:58 
AnswerRe: Connected or not? Pin
ThatsAlok20-Feb-05 19:11
ThatsAlok20-Feb-05 19:11 
AnswerRe: Connected or not? Pin
David Crow21-Feb-05 4:10
David Crow21-Feb-05 4:10 
AnswerRe: Connected or not? Pin
Michael Dunn21-Feb-05 6:58
sitebuilderMichael Dunn21-Feb-05 6:58 
GeneralTitle bar Color Pin
Anonymous20-Feb-05 18:54
Anonymous20-Feb-05 18:54 
QuestionHow to fix first four coumns of the List ctrl and all other columns to allow scrolling Pin
sureshpillai20-Feb-05 18:40
sureshpillai20-Feb-05 18:40 
GeneralPassing values of object. Getting garbage. Pin
macrophobia20-Feb-05 18:25
macrophobia20-Feb-05 18:25 
GeneralRe: Passing values of object. Getting garbage. Pin
David Nash20-Feb-05 22:02
David Nash20-Feb-05 22:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.