Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Which is best (obj != null) or ( obj == null) ?

Which is best (obj != null) or ( obj == null) ?

Scheduled Pinned Locked Moved C#
question
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vytheese
    wrote on last edited by
    #1

    Object obj = null; if(obj == null) Console.Writeline("null"); if(obj != null) Console.Writeline("not null"); In above which will execute faster. == or != :mad: Just curious...

    Regards, Vythees Miles to go before sleep...

    V M C 3 Replies Last reply
    0
    • V vytheese

      Object obj = null; if(obj == null) Console.Writeline("null"); if(obj != null) Console.Writeline("not null"); In above which will execute faster. == or != :mad: Just curious...

      Regards, Vythees Miles to go before sleep...

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      Does == or != has much vertical differences?

      Vasudevan Deepak Kumar Personal Homepage
      Tech Gossips
      A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

      1 Reply Last reply
      0
      • V vytheese

        Object obj = null; if(obj == null) Console.Writeline("null"); if(obj != null) Console.Writeline("not null"); In above which will execute faster. == or != :mad: Just curious...

        Regards, Vythees Miles to go before sleep...

        M Offline
        M Offline
        MarkB777
        wrote on last edited by
        #3

        I imagine they would be the same.

        Mark Brock Click here to view my blog

        1 Reply Last reply
        0
        • V vytheese

          Object obj = null; if(obj == null) Console.Writeline("null"); if(obj != null) Console.Writeline("not null"); In above which will execute faster. == or != :mad: Just curious...

          Regards, Vythees Miles to go before sleep...

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          vytheese wrote:

          In above which will execute faster. == or !=

          Considering that your PC probably runs at 2+ billion clock cycles per second, and such an operation is so trivial compared to other instructions that could be issued, does it really matter? Seriously, the jump that's going to happen after the conditional check is going to cost more than the check because of the way processor pipelining works. And the jump is going to happen regardless of the type of check you are performing. In short you are over optimising. Finally, just so you get your question answered - They cost the same in terms of processor cycles.

          Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Introduction to LINQ to XML (Part 1) - (Part 2) My website | Blog

          R V 2 Replies Last reply
          0
          • C Colin Angus Mackay

            vytheese wrote:

            In above which will execute faster. == or !=

            Considering that your PC probably runs at 2+ billion clock cycles per second, and such an operation is so trivial compared to other instructions that could be issued, does it really matter? Seriously, the jump that's going to happen after the conditional check is going to cost more than the check because of the way processor pipelining works. And the jump is going to happen regardless of the type of check you are performing. In short you are over optimising. Finally, just so you get your question answered - They cost the same in terms of processor cycles.

            Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Introduction to LINQ to XML (Part 1) - (Part 2) My website | Blog

            R Offline
            R Offline
            Reelix
            wrote on last edited by
            #5

            It's like asking you (As a Human Being) Which can you solve faster: 1 + 1 or 5 * 5 They're both SO easy (I hope...) that the time it takes you to do the calculations is SO small, the time taken is actually negligible in the actual scheme of things (The time taken from being given the question, to producing an answer), even though the second question (Being multiplication, with higher numbers) is obviously harder (Relatively...) To Sum Up: It doesnt really matter :)

            -= Reelix =-

            1 Reply Last reply
            0
            • C Colin Angus Mackay

              vytheese wrote:

              In above which will execute faster. == or !=

              Considering that your PC probably runs at 2+ billion clock cycles per second, and such an operation is so trivial compared to other instructions that could be issued, does it really matter? Seriously, the jump that's going to happen after the conditional check is going to cost more than the check because of the way processor pipelining works. And the jump is going to happen regardless of the type of check you are performing. In short you are over optimising. Finally, just so you get your question answered - They cost the same in terms of processor cycles.

              Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Introduction to LINQ to XML (Part 1) - (Part 2) My website | Blog

              V Offline
              V Offline
              vytheese
              wrote on last edited by
              #6

              So in that terms, Is there will be a diffrence between JNE or JE instructions.

              Colin Angus Mackay wrote:

              In short you are over optimising.

              Yes I agree with the above. ;)

              Regards, Vythees Miles to go before sleep...

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups