I am surprised to observe that mono is faster than .NET. Does anyone know why is it so? I was expecting mono to be slower than .NET but wasnt the case atleast with my experiments.
I have a windows xp laptop with .NET framework. I am running CentOS on vmware vmplayer on top of windows xp. I wanted to try mono. So grabbed the Mono 2.6.1 sources and installed it on CentOS in vmplayer. I have writen a test webservice application using .Net 2.0 executed it on wndows, it worked, I transferred the binary to the centos in the vmplayer without any recompilation and executed it on centos. Hurray it worked! Life is good but then something else lured my attention. The execution of the application on centos seemed to be faster. I did not believe my eyes.
To confirm my observation, I eliminated network out of the equation because network reponse depends on lot of external factors.
I grabbed small dummy loop code from internet, compiled it in visual studio executed in windows as well as CentOS, the results are as follows
Output on windows console is HelloConsole\bin\Debug>HelloConsole.exe
Result =2.66666664666712E+24
37443.6077769661 ms
Output on Centos console is [rupert@bagvapp Math.Pow]$ mono HelloConsole.exe
Result =2.66666664666712E+24
28790.6286 ms
If anyone can explain this behavior,that would be great. my layman's understanding is Mono's implementation is more efficient than .NET framework. Even if I assume Mono's Math implementation is only efficient. But lot of implementations like processing financial data, graphics calculations depend lot on Math library. It would be more interesting to perform the test on Mono/Centos directly without vmware but that needs some time. I will give it a try may be next weekend.
public static void DummyLoop()
{
double sumOfPowers = 0;
int count = Convert.ToInt32(ConfigurationManager.AppSettings["count"]);
for (int i = 0; i < count; i++)
{
sumOfPowers += Math.Pow(i, 2);
}
Console.WriteLine("Result =" + sumOfPowers);
}
static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
DummyLoop();
stopWatch.Stop();
double ms = (stopWatch.ElapsedTicks * 1000.0) / Stopwatch.Frequency;
Console.WriteLine(string.Concat(ms.ToString(), " ms"));
Console.ReadLine();
}