shervin's blog

By shervin, history, 9 years ago, In English

Hello,
i am just curious, i want to know if we have a bool like X, and if we want to check if it is 0, which if statement is more efficient This->if(!X) or This->if(x^1).(i checked the asm code and the codes were not the same so i think they defer from one another.)
Thanks.

  • Vote: I like it
  • -19
  • Vote: I do not like it

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

can someone give me any reason for the down-votes?
did i write something wrong??
Or everyone in cf is in a bad mood?

  • »
    »
    9 years ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    I can explain downvotes.

    1. This is something completely unimportant. Differences between them will be very small.

    2. You can easily check it by yourself.

    • »
      »
      »
      9 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      1. i said "I am just curious".
      2. i dont know assembly.
      • »
        »
        »
        »
        9 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        You don't need to know assembly to make run-time tests.

        • »
          »
          »
          »
          »
          9 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          run-time tests are useless for this situation.
          converting to asm may help because assembly op codes i think have specific run times on specific hardware.

          • »
            »
            »
            »
            »
            »
            9 years ago, # ^ |
              Vote: I like it +14 Vote: I do not like it

            Dafuq? You want to test EFFICIENCY and that is exactly what run-time tests will show x_0.

            • »
              »
              »
              »
              »
              »
              »
              9 years ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              i tested with a for to 10^6 and the outcome was same for me.....(But opcodes in asm DIFFER!)

              • »
                »
                »
                »
                »
                »
                »
                »
                9 years ago, # ^ |
                Rev. 2   Vote: I like it 0 Vote: I do not like it

                There are 2 variable x, y. One little funny thing about variables is that they can have the same value (x = 4 and y = 4 for example).

                Yes, x and y are different variables, but it doesn't mean that they can't hold the same value.

                It's the same thing with opcodes. Different opcodes doesn't have to mean different running times. It's perfectly normal.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  9 years ago, # ^ |
                  Rev. 2   Vote: I like it 0 Vote: I do not like it

                  Yes x, y can have the same value BUT when it comes to efficiency, it matters how MANY times you use X and you use Y.
                  when i use cat on my asm, there are 2 movl's and one subl and 2 function calls for X^1 and 1 movl and 3 function calls for !X.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  9 years ago, # ^ |
                    Vote: I like it 0 Vote: I do not like it

                  nvm, seems this conversation is going no-where, i have to sleep. Goodnight.

          • »
            »
            »
            »
            »
            »
            9 years ago, # ^ |
              Vote: I like it +1 Vote: I do not like it

            If you think that way, trying to understand it from assembly code is also useless because assembly code is compiler-dependent.

            • »
              »
              »
              »
              »
              »
              »
              9 years ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              i know thats why i need someone that is familiar with "GAS"(gnu assembler).

      • »
        »
        »
        »
        9 years ago, # ^ |
          Vote: I like it +3 Vote: I do not like it

        shervin, you know assembly. Don't lie to others ;)

»
9 years ago, # |
  Vote: I like it +5 Vote: I do not like it

I'm not sure about efficiency, but I would definitely go with the first one since it's much more readable, and it doesn't really matter because difference -if there is any- would be negligible.