View Single Post
Old 02-12-2007, 05:23 AM   #8 (permalink)
Ray
Forum Novice
 
Join Date: Jul 2004
Location: Switzerland
Age: 25
Posts: 234
Default

Quote:
Originally Posted by mordero View Post
hmmm whoops yeah, i just remembered reading that somewhere. My bad
Could have been a book on c/c++, where the size of an 'int' depends on the compiler. In .Net, they're all fixed size. However, a real change happens to all pointers (and references) as they have to address the whole 64bit scope.




Quote:
Originally Posted by IHaveRegistered View Post
Code:
if( ((from != null) || (from.Map != Map.Internal)) || (!from.Deleted) )
{
    //code
}

or

if( from != null )
{
    if( from.Map != Map.Internal )
    {
        if( !from.Deleted )
        {
            //code
        }
    }
}
What one of those two would be faster? For me, the second looks more organized. But both end up accomplishing the exact same task. Is there actually any difference in performance? Or anything else for that matter?
Those 2 statements arent doing the same thing, cuz the first one would cause an exception if from is null. A OR concatination always checks all statements until one is true. The second one uses AND, which checks all statements until one is false (Only execute code if all checks succeeded).
However, if both were AND, this would probably lead to the same performance as it does the same thing (assuming there are no variables that run out of scope). Away from that, you'll find better ways to improve performance than comparing two if's against each other.


-----
1: not sure about that, but under the hood, this should be compiled to just the same code afaik.
2: No, double stores less digits. An integral value like long is stored 'as is'. A floating point value is stored with a mantissa and an exponent to its base. These types are also called 'approximate numbers', as they have a limited precision. You can use double to store much higher values than with int64, but they are of limited precision. Only the higest 16 digits of a number are stored here.
3:decimal has another base. Unlike the other types, it's 10 based, double is 2 based, leading to those wonderful outputs like 0.8 - 0.1 = 0.699999~. And it's not an approximate number. A decimal stores more 'digits' than a double, but less on the left side of the point, it's more precise which is really importent if you're calculating with, say, currencies.
4:1byte is the smallest chunk of memory a processor can handle. Eheres nothing more to say about this, its a technology restriction. Except of: .Net usually pads even 8bit memory to 32bit.
5: No, this is just the same IL code. A difference with this 2 statements is most likley of inaccurate testing - you can't test this only with one run, as other processes on your system can interfer with the test.
6: Try to run it without the F. It won't compile. The F is there to tell the compiler that this constant is a float-type. Without it, the compiler assumes it to be a double and it cant implicitly convert it to float.
Ray is offline   Reply With Quote