Click here to Skip to main content
15,888,240 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Better Way [modified] Pin
sunit55-Jun-06 19:47
sunit55-Jun-06 19:47 
AnswerRe: Better Way Pin
Laxman Auti5-Jun-06 19:57
Laxman Auti5-Jun-06 19:57 
GeneralRe: Better Way Pin
HakunaMatada5-Jun-06 20:08
HakunaMatada5-Jun-06 20:08 
GeneralRe: Better Way Pin
Viorel.5-Jun-06 20:10
Viorel.5-Jun-06 20:10 
GeneralRe: Better Way Pin
Maxwell Chen5-Jun-06 20:18
Maxwell Chen5-Jun-06 20:18 
GeneralRe: Better Way Pin
Viorel.5-Jun-06 20:36
Viorel.5-Jun-06 20:36 
AnswerRe: Better Way Pin
Maxwell Chen5-Jun-06 21:29
Maxwell Chen5-Jun-06 21:29 
GeneralRe: Better Way Pin
Viorel.5-Jun-06 22:28
Viorel.5-Jun-06 22:28 
I think it is not a problem if the compiler generates different code for looking-similar fragments when the optimization is turned off.

Since we are interested in faster code, we should turn the optimization on. But in this case we should take care that the compiler will not completely remove the fragments we investigate in our experiments. In order to prevent removing or in-lining of tested function and calls, we have to prepare our code using directives like volatile and __declspec(noinline).

The experimental code for comparing code with optimizations can look like this:

int __declspec(noinline) TestI(int n)
{
    volatile static int k = n; // prevents removing of calls
    if(n==0 || n==1)
        return n;
    return -1;
}

int __declspec(noinline) TestO(int n)
{
    volatile static int k = n; // prevents removing of calls
    return (n == 0 || n == 1) ? n : -1;
}

void main()
{
    const long N = 1000000000L;
    DWORD s = ::GetTickCount();
    for(long i = 0; i < N; ++i)
    {
        TestI(3); 
    }
    DWORD t = ::GetTickCount() - s;
    printf("%i\n", t);
    s = ::GetTickCount();
    for(long i = 0; i < N; ++i) 
    { 
        TestO(3); 
    }
    t = ::GetTickCount() - s;
    printf("%i\n", t);
}

In this case, the average time in case of VC++ 2003 compiler does not differ.

It should be more ways for performing accurate code-generation comparison in case the optimization is turned on.

In addition, this can be better checked by specifying a compiler option for generating intermediate Assembler code.
GeneralRe: Better Way Pin
Maxwell Chen5-Jun-06 23:06
Maxwell Chen5-Jun-06 23:06 
GeneralRe: Better Way Pin
Viorel.5-Jun-06 23:20
Viorel.5-Jun-06 23:20 
GeneralRe: Better Way Pin
Maxwell Chen5-Jun-06 23:29
Maxwell Chen5-Jun-06 23:29 
AnswerRe: Better Way Pin
Hamid_RT5-Jun-06 22:22
Hamid_RT5-Jun-06 22:22 
QuestionUPDATE DATA Pin
yogendra kaushik5-Jun-06 19:02
yogendra kaushik5-Jun-06 19:02 
AnswerRe: UPDATE DATA Pin
Maxwell Chen5-Jun-06 19:14
Maxwell Chen5-Jun-06 19:14 
QuestionHow to know that application is closed. that was launched by ShellExecute() Pin
zahid_ash5-Jun-06 18:50
zahid_ash5-Jun-06 18:50 
AnswerRe: How to know that application is closed. that was launched by ShellExecute() Pin
Ganesh_T5-Jun-06 18:55
Ganesh_T5-Jun-06 18:55 
GeneralRe: How to know that application is closed. that was launched by ShellExecute() Pin
zahid_ash5-Jun-06 18:58
zahid_ash5-Jun-06 18:58 
GeneralRe: How to know that application is closed. that was launched by ShellExecute() Pin
khan++5-Jun-06 19:06
khan++5-Jun-06 19:06 
AnswerRe: How to know that application is closed. that was launched by ShellExecute() Pin
khan++5-Jun-06 18:58
khan++5-Jun-06 18:58 
AnswerRe: How to know that application is closed. that was launched by ShellExecute() Pin
Laxman Auti5-Jun-06 20:04
Laxman Auti5-Jun-06 20:04 
AnswerRe: How to know that application is closed. that was launched by ShellExecute() Pin
sunit55-Jun-06 20:11
sunit55-Jun-06 20:11 
GeneralRe: How to know that application is closed. that was launched by ShellExecute() Pin
sunit55-Jun-06 20:37
sunit55-Jun-06 20:37 
AnswerRe: How to know that application is closed. that was launched by ShellExecute() Pin
Viorel.5-Jun-06 20:28
Viorel.5-Jun-06 20:28 
AnswerRe: How to know that application is closed. that was launched by ShellExecute() Pin
2249175-Jun-06 23:00
2249175-Jun-06 23:00 
Questionrunning an application using command prompt Pin
zahid_ash5-Jun-06 18:45
zahid_ash5-Jun-06 18:45 

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.