Thread: Which is Faster....

  1. #1
    Unregistered
    Guest

    Which is Faster....

    BOOL jon;

    jon = 0;

    or

    if(jon!=0)



    basically, is it faster to check the state of a BOOL or to save to it?

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Saving a bool and making a condtional branch are two different things, you can't use one over the other. Perhaps you are wondering about saving the result of some condition in a bool so you don't have to make the test multiple times?
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Unregistered
    Guest
    No. I am asking which line of code runs faster. For my purposes, I need to know which is faster, tho I understand that they do not do the same thing.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Depends on your compiler

    Look at the assembler code it generates

  5. #5
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    I think it's the if statement that takes more time.
    It also depends if the if statement is true or not (because of the jump instruction).

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Post further replies here
    http://www.cprogramming.com/cboard/s...threadid=21897

    Duplicate post

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Faster bitwise operator
    By Yarin in forum C++ Programming
    Replies: 18
    Last Post: 04-29-2009, 01:56 PM
  2. Faster way of printing to the screen
    By cacophonix in forum C Programming
    Replies: 16
    Last Post: 02-04-2009, 01:18 PM
  3. Which Operation is Faster "=" or "+=" ?
    By thetinman in forum C++ Programming
    Replies: 37
    Last Post: 06-06-2007, 07:29 PM
  4. does const make functions faster?
    By MathFan in forum C++ Programming
    Replies: 7
    Last Post: 04-25-2005, 09:03 AM
  5. Floating point faster than fixed-point
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-08-2001, 11:34 PM