Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mono Project: Why is mono faster than .NET?

Tags:

c#

.net

mono

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();     } 
like image 362
funwithcoding Avatar asked Mar 07 '10 19:03

funwithcoding


People also ask

What is the difference between .NET and Mono?

NET is platform dependent, Mono allows developers to build Linux and cross- platform applications. Mono's . NET implementation is based on the ECMA standards for C#. This paper examines both of these programming environments with the goal of evaluating the performance characteristics of each.

When should I use .NET Core?

NET Core is used to create server applications that run on Windows, Linux and Mac. It does not currently support creating desktop applications with a user interface. Developers can write applications and libraries in VB.NET, C# and F# in both runtimes.

Is Mono dead?

Mono is the first child in the franchise to have his entire face visible at one point. He is the only protagonist who is not Six who does not die at the end of his adventure.


1 Answers

This was a discussion about this on the Mono mailing list not too long ago. The reasoning they provided is Mono is extremely optimized under Linux (exactly how did not seem to be mentioned). But Mono is not the only variable here, if you are running Mono on Linux. It's a different OS, different process schedulers and various kernel level subsystems can have a markedly different effects on performance, independent of the Mono team's work. Mono also makes heavy use of compiler intrinsics, which .NET may or may not do.

However, most of the time on a Mono on Windows vs .NET on Windows comparison, you might find .NET beating Mono more often then not. But even then, Mono might not always lose. In fact, for code specifically optimized for Mono (eg: using Mono.SIMD), you might get an order of magnitude better performance on Mono vs .NET, regardless of platform.

like image 179
joemoe Avatar answered Sep 24 '22 17:09

joemoe