Which is best (obj != null) or ( obj == null) ?
-
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...
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 -
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...
I imagine they would be the same.
Mark Brock Click here to view my blog
-
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...
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
-
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
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 =-
-
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