Considering the 1st part of your thread here, the int vs Int32. What I find weird is they are treated the same when you output their Type...
Take the following code
Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace SpeedTesting
{
class Program
{
static Stopwatch _stopWatch;
static void Main(string[] args)
{
_stopWatch = new Stopwatch();
for( int b = 0; b < 15; b++ )
{
_stopWatch.Start();
for( int i = 0; i < int.MaxValue; i++ )
{
int a = 0;
}
_stopWatch.Stop();
Output(typeof(int), int.MaxValue, _stopWatch.ElapsedMilliseconds);
_stopWatch.Reset();
_stopWatch.Start();
for( int i = 0; i < int.MaxValue; i++ )
{
Int32 a = 0;
}
_stopWatch.Stop();
Output(typeof(Int32), int.MaxValue, _stopWatch.ElapsedMilliseconds);
_stopWatch.Reset();
Console.WriteLine();
}
Console.ReadLine();
}
private static void Output(Type type, int times, long milliSeconds)
{
Console.WriteLine("Called ({0}) {1} times in {2} milliseconds", type, times, milliSeconds);
}
}
}
You will notice that my output of the variable is by Type.
However, here is the output of the application...
Code:
Called (System.Int32) 2147483647 times in 6729 milliseconds
Called (System.Int32) 2147483647 times in 6627 milliseconds
Called (System.Int32) 2147483647 times in 6691 milliseconds
Called (System.Int32) 2147483647 times in 6666 milliseconds
Called (System.Int32) 2147483647 times in 6715 milliseconds
Called (System.Int32) 2147483647 times in 6665 milliseconds
Called (System.Int32) 2147483647 times in 6668 milliseconds
Called (System.Int32) 2147483647 times in 6591 milliseconds
Called (System.Int32) 2147483647 times in 6597 milliseconds
Called (System.Int32) 2147483647 times in 6542 milliseconds
Called (System.Int32) 2147483647 times in 6573 milliseconds
Called (System.Int32) 2147483647 times in 6551 milliseconds
Called (System.Int32) 2147483647 times in 6764 milliseconds
Called (System.Int32) 2147483647 times in 6665 milliseconds
Called (System.Int32) 2147483647 times in 6677 milliseconds
Called (System.Int32) 2147483647 times in 6641 milliseconds
Called (System.Int32) 2147483647 times in 6620 milliseconds
Called (System.Int32) 2147483647 times in 6762 milliseconds
Called (System.Int32) 2147483647 times in 6766 milliseconds
Called (System.Int32) 2147483647 times in 6639 milliseconds
Called (System.Int32) 2147483647 times in 6641 milliseconds
Called (System.Int32) 2147483647 times in 6629 milliseconds
Called (System.Int32) 2147483647 times in 6678 milliseconds
Called (System.Int32) 2147483647 times in 6624 milliseconds
I cut it short cause i didnt wanan run it 15 times nor did i need to after just these few results. You can see that indeed Int32 is slightly faster then the standard int. But still the fact that its refered to as the same Type is really weird.
Now just to make sure there wasnt some odd fluke since i called int first and Int32 second, i reversed the statements as follows
Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace SpeedTesting
{
class Program
{
static Stopwatch _stopWatch;
static void Main(string[] args)
{
_stopWatch = new Stopwatch();
for( int b = 0; b < 15; b++ )
{
_stopWatch.Start();
for( int i = 0; i < int.MaxValue; i++ )
{
Int32 a = 0;
}
_stopWatch.Stop();
Output(typeof(int), int.MaxValue, _stopWatch.ElapsedMilliseconds);
_stopWatch.Reset();
_stopWatch.Start();
for( int i = 0; i < int.MaxValue; i++ )
{
int a = 0;
}
_stopWatch.Stop();
Output(typeof(Int32), int.MaxValue, _stopWatch.ElapsedMilliseconds);
_stopWatch.Reset();
Console.WriteLine();
}
Console.ReadLine();
}
private static void Output(Type type, int times, long milliSeconds)
{
Console.WriteLine("Called ({0}) {1} times in {2} milliseconds", type, times, milliSeconds);
}
}
}
and sure enough it was a fluke, the seconds statement is still called faster then the first, but not everytime... Odd eh?
Code:
Called (System.Int32) 2147483647 times in 6768 milliseconds
Called (System.Int32) 2147483647 times in 6658 milliseconds
Called (System.Int32) 2147483647 times in 6660 milliseconds
Called (System.Int32) 2147483647 times in 6648 milliseconds
Called (System.Int32) 2147483647 times in 6765 milliseconds
Called (System.Int32) 2147483647 times in 6651 milliseconds
Called (System.Int32) 2147483647 times in 6679 milliseconds
Called (System.Int32) 2147483647 times in 6672 milliseconds
Called (System.Int32) 2147483647 times in 6686 milliseconds
Called (System.Int32) 2147483647 times in 6693 milliseconds
Called (System.Int32) 2147483647 times in 6622 milliseconds
Called (System.Int32) 2147483647 times in 6659 milliseconds
Called (System.Int32) 2147483647 times in 6763 milliseconds
Called (System.Int32) 2147483647 times in 6632 milliseconds
Called (System.Int32) 2147483647 times in 6565 milliseconds
Called (System.Int32) 2147483647 times in 6649 milliseconds
Called (System.Int32) 2147483647 times in 6687 milliseconds
Called (System.Int32) 2147483647 times in 6736 milliseconds
Called (System.Int32) 2147483647 times in 6629 milliseconds
Called (System.Int32) 2147483647 times in 6598 milliseconds
Called (System.Int32) 2147483647 times in 6677 milliseconds
Called (System.Int32) 2147483647 times in 6745 milliseconds
Called (System.Int32) 2147483647 times in 6617 milliseconds
Called (System.Int32) 2147483647 times in 6594 milliseconds
I find this odd and interesting
