Thread: Just a nitpicky question

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    Talking Just a nitpicky question

    Hey, I just thought of a really really nitpicky question. Does the ! operator (it is an operator, right?) make any difference in speed whatsoever? I mean, would there be any difference at all in the speed of these code examples?

    Code:
    //Clip 1
    bool done = false;
    while(!done)
         //stuff
    
    //Clip 2
    bool notDone = true;
    while(notDone)
         //stuff
    It doesn't really matter to me, and I know that most people would use the first code example, but just had a sudden curiosity attack.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Some speed... probably.

    Noticeable... not really


    However, your compiler might optimize something like that.

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    I'm going to say no.
    In assembly that's just a difference of conditional jumps. JE vs. JNE (Jump if Equal, Jump if Not Equal)
    This is what VC6 output:

    Code:
    while (!done)
    0040117C  mov	eax,dword ptr [ebp-4]
    0040117F  and	eax,0FFh
    00401184  test	eax,eax
    00401186  jne	main+48h
    Code:
    while (notdone)
    0040117C  mov	eax,dword ptr [ebp-4]
    0040117F  and	eax,0FFh
    00401184  test	eax,eax
    00401186  je	main+48h
    As you can see, the only difference between the two is the different jumps. I doubt one is any faster than the other.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I mean, would there be any difference at all in the speed of these code examples?
    Before optimization, possibly, after optimization, I would be very surprised.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Ok, thanks my curiosity is satisfied.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM