Click here to Skip to main content
15,890,438 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionEfficiency Pin
Ofer Gross3-Mar-10 2:33
Ofer Gross3-Mar-10 2:33 
AnswerRe: Efficiency Pin
Eugen Podsypalnikov3-Mar-10 2:40
Eugen Podsypalnikov3-Mar-10 2:40 
AnswerRe: Efficiency Pin
Covean3-Mar-10 2:58
Covean3-Mar-10 2:58 
AnswerRe: Efficiency Pin
David Crow3-Mar-10 2:58
David Crow3-Mar-10 2:58 
AnswerRe: Efficiency Pin
CPallini3-Mar-10 3:18
mveCPallini3-Mar-10 3:18 
GeneralRe: Efficiency Pin
Covean3-Mar-10 3:44
Covean3-Mar-10 3:44 
GeneralRe: Efficiency Pin
CPallini3-Mar-10 6:47
mveCPallini3-Mar-10 6:47 
GeneralRe: Efficiency Pin
Covean3-Mar-10 22:22
Covean3-Mar-10 22:22 
But it seems that I'm right, after I made some performance tests (1 billion loop).

with Check:

    bool bTest = false;
    LARGE_INTEGER lFreq;
    LARGE_INTEGER lStart;
    LARGE_INTEGER lEnd;
    QueryPerformanceFrequency(&lFreq);
    QueryPerformanceCounter(&lStart);    
    _asm
    {
        push ecx
        mov ecx, 1000000000
_loop:
        cmp bTest, 0
        je  _set        
        sub ecx, 1
        jnz _loop
        jmp _end
_set:
        mov bTest, 1
        sub ecx, 1
        jnz _loop
_end:
        pop ecx
    }
    QueryPerformanceCounter(&lEnd);


without Check:

    bool bTest = false;
    LARGE_INTEGER lFreq;
    LARGE_INTEGER lStart;
    LARGE_INTEGER lEnd;
    QueryPerformanceFrequency(&lFreq);
    QueryPerformanceCounter(&lStart);   
    _asm
    {
        push ecx
        mov ecx, 1000000000
_loop:
        mov bTest, 1        
        sub ecx, 1
        jnz _loop
        pop ecx
    }

    QueryPerformanceCounter(&lEnd);


Here are the results of the test:

with Check:
1270916680 ns
1263151000 ns
1266200680 ns
1263518040 ns
1261185600 ns
average: 1264994400 ns for an one billion loop

without Check:
1268685200 ns
1264999280 ns
1268999120 ns
1263301960 ns
1263604200 ns
average: 1265917952 ns for an one billion loop

So writing it every time is a little bit slower than checking the value (on my cpu).
Greetings
Covean

GeneralRe: Efficiency Pin
CPallini3-Mar-10 23:13
mveCPallini3-Mar-10 23:13 
GeneralRe: Efficiency Pin
Covean3-Mar-10 23:28
Covean3-Mar-10 23:28 
GeneralRe: Efficiency Pin
CPallini3-Mar-10 23:37
mveCPallini3-Mar-10 23:37 
GeneralRe: Efficiency Pin
Covean3-Mar-10 23:48
Covean3-Mar-10 23:48 
GeneralRe: Efficiency Pin
KarstenK3-Mar-10 4:19
mveKarstenK3-Mar-10 4:19 
AnswerRe: Efficiency Pin
Alain Rist3-Mar-10 3:53
Alain Rist3-Mar-10 3:53 
AnswerRe: Efficiency Pin
Alan Balkany3-Mar-10 4:22
Alan Balkany3-Mar-10 4:22 
GeneralRe: Efficiency Pin
Covean3-Mar-10 4:35
Covean3-Mar-10 4:35 
GeneralRe: Efficiency Pin
Alan Balkany3-Mar-10 4:41
Alan Balkany3-Mar-10 4:41 
GeneralRe: Efficiency Pin
CPallini3-Mar-10 7:12
mveCPallini3-Mar-10 7:12 
AnswerRe: Efficiency Pin
Chris Losinger3-Mar-10 5:04
professionalChris Losinger3-Mar-10 5:04 
AnswerRe: Efficiency Pin
supercat93-Mar-10 9:19
supercat93-Mar-10 9:19 
AnswerRe: Efficiency [modified] Pin
Covean3-Mar-10 20:42
Covean3-Mar-10 20:42 
Questionbind(...) in tcp is failed when connected twice C++ Pin
janaswamy uday3-Mar-10 2:14
janaswamy uday3-Mar-10 2:14 
AnswerRe: bind(...) in tcp is failed when connected twice C++ Pin
Eugen Podsypalnikov3-Mar-10 3:03
Eugen Podsypalnikov3-Mar-10 3:03 
GeneralRe: bind(...) in tcp is failed when connected twice C++ Pin
janaswamy uday3-Mar-10 3:34
janaswamy uday3-Mar-10 3:34 
GeneralRe: bind(...) in tcp is failed when connected twice C++ Pin
Eugen Podsypalnikov3-Mar-10 3:44
Eugen Podsypalnikov3-Mar-10 3:44 

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.