speed difference

i was wondering how much speed difference there would be between bool int long and such when we used a while loop since it is very important to make your code run faster.
here is what i worked on:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main(int argc, char* args[])
{
    Uint32 time_Now, time_Start;
    int a;

    bool quit = false;
    time_Start = SDL_Getticks();
    while(quit != true)
    {
        a++;
        time_Now = SDL_Getticks();
        if(time_Now - time_Start >= 1000)
        {
            quit = true;
        }
    }
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main(int argc, char* args[])
{
    Uint32 time_Now, time_Start;
    int a;

    long quit = 0;
    time_Start = SDL_Getticks();
    while(quit != 1)
    {
        a++;
        time_Now = SDL_Getticks();
        if(time_Now - time_Start >= 1000)
        {
            quit = 1;
        }
    }
}

as you see both quits while loop after a second program started running.

where i got cracked is both runs around 35m at a second. shouldnt bool run faster since bool is 1 bit and long is 4 bytes (as far as i know)?
thx in advance for your answers
You do nearly no operations with the "quit" and there is only one. Show the assembly of both versions; they might be surprisingly similar.

I bet that lines 11 and 12 use much more time than lines 8 and 14.

The CPU operates with registers. A register has a size. Do you think that 4 bytes does not fit into a register? Do you think that there is a different instruction in CPU to check whether one bit in register is 0 and to check whether 32 bits are all 0?

If you have a billion bool or long, then memory access starts to play a role. Sure, you might be able to pack booleans so that you can handle 32 at a time, but you can vectorize long as well. Xeon Phi, 512 bit registers and N "cores" ...


PS. You should be able to test the size of bool and long in your system. I don't think that "1 bit" is an answer.
thx for the answer.

but yeah i should be able to check and i should.

but since i m currently at a formal school i m unable to use my laptop(all electronics are forbidden) so i work on papers(read articles etc. etc.) when i get home i will test many things. and i m messaging these at schools own computer lab which sucks almost everything is forbidden(installing programs, running unknown programs, some websites etc. etc.)

so anyways thx for your detailed answer

and then when i checked it runs 35m at a sec. yeah that was before i come school which was 3 days ago
Last edited on
Topic archived. No new replies allowed.