posts - 4, comments - 17, trackbacks - 5

My Links

News

Article Categories

Archives

Post Categories

Favourite Sites

Mono vs. .NET Performance Test

My past experiences with Mono left me unimpressed because of it's speed issues, in some cases the .NET Framework runing six times faster. But because a lot of people claim that Mono gets faster with every build, today I decided to run a small series of tests to see if there have been any improvements. The results have been very surprising as you will see below.

First of all, this is the C# code used for my tests. Sorry if it's a little messy :-)

using System;

using System.Collections;

 

namespace TestNamespace

{

      public class TestClass

      {

            static long ticks = 0;

 

            public static void InitTicks()

            {

                  TestClass.ticks = DateTime.Now.Ticks;

            }

 

            public static void ShowTime(string str)

            {

                  long newTicks = DateTime.Now.Ticks;

                  //milliseconds, not Microsoft :)

                  double ms = (newTicks - TestClass.ticks) / TimeSpan.TicksPerMillisecond;

                  Console.WriteLine("{0}{1} ms", str.PadRight(35, '.'), ms);

                  TestClass.ticks = DateTime.Now.Ticks;

            }

 

 

            public static void Test1()

            {

                  ArrayList a = new ArrayList();

                  for(int i=0;i<1000000;i++)

                  {

                        string str = i.ToString();

                        a.Add(str);

                  }

 

                  ShowTime("ArrayList strings test");

 

                  System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();

 

                  Random rnd = new Random();

 

                  foreach(object strObj in a)

                  {

                        strBuilder.Append(strObj as string);

                        strBuilder.Append(rnd.Next().ToString());

                  }

 

                  string s = strBuilder.ToString();

 

                  if(s == "Dsadasdasdsa")

                  {

                        throw(new Exception("no way..."));

                  }

 

                  ShowTime("StringBuilder test");

            }

 

            public static void Test2()

            {

                  int i = 0;

                  double d = 0.0;

                  for(i=0; i<1000000000; i++)

                  {

                        d += i;

                  }

 

                  double d2 = d/2;

 

                  ShowTime("Integer & Floating ADD");

            }

            public static void Test3()

            {

                  int i = 0;

                  int sum = 0;

 

                  for(i=0;i<100000;i++)

                  {

                        try

                        {

                              if(i is int)

                              {

                                    throw(new Exception("the i integer is an integer.. oh no..."));

                              }

                        }

                        catch(Exception ex)

                        {

                              if(ex is NotImplementedException)

                              {

                                    Console.Write("who's responsable for this ?");

                              }

                        }

                  }

 

                  int res = sum/2;

                  if(res == -321)

                        throw(new Exception("this is odd"));

 

                  ShowTime("Exception test");

            }

            public static void Recursive(string str)

            {

                  string name = System.Reflection.MethodBase.GetCurrentMethod().Name;

 

                  if(str.Substring(0, name.Length) == name)

                  {

                        int i = Convert.ToInt32(str.Substring(name.Length));

                        if(i < 1000)

                        {

                  //          Console.Write(i.ToString()+"\n");

                              Recursive(name + (i+1).ToString());

                        }

                  }

           

            }

 

            public static void Test4()

            {

                  for(int i=0;i<1000;i++)

                  {

                        Recursive("Recursive0");

                  }

 

                  ShowTime("Reflection and recursion");

            }

            public static void Main()

            {

                  InitTicks();

 

                  Test1();

                  Test2();

                  Test3();

                  Test4();

            }

      }

}

This code contains 5 tests:

Test name

Function name

Details

ArrayList test

Test1, 1st part

1 million strings are inserted into an ArrayList.

StringBuilder test

Test1, 2nd part

The strings from the ArrayList are appended to a StringBuilder.

Integer & Floating ADD test

Test2

An integer is added to a double 1 billion times.

Exception test

Test3

100.000 exceptions are thrown.

Recursion and reflection test

Test4

A recursive function that calls GetCurrentMethod() is called for 1000 times. (see more details in code)

I almost forgot to specify my configuration: Athlon XP 2600+, 1 GB RAM PC2700, 80 GB 7200 2MB HDD, WindowsXP SP2. Now, to the really interesting part.

There are the results when compiling with the optimizations off. As you can see, it's unbelievable how similar the timings are.

-----------------------------------------------------------------------------
Running Mono binary:
ArrayList strings test.............890 ms
StringBuilder test.................1046 ms
Integer & Floating ADD.............2000 ms
Exception test.....................890 ms
Reflection and recursion...........3859 ms
-----------------------------------------------------------------------------
Running Framework binary:
ArrayList strings test.............921 ms
StringBuilder test.................1062 ms
Integer & Floating ADD.............1968 ms
Exception test.....................859 ms
Reflection and recursion...........3859 ms
-----------------------------------------------------------------------------

When I turned the optimizations on in both CSC and MCS (the Mono C# compiler) the Integer & Floating ADD Test ran two times faster with the .NET Framework. However, because this is a very simple test, the optimizations used may not be appliable in any real-life applications. Other than that there are no noticeable differences between the timings obtained with or without the optimize+ flag. That's right, the same flags are used in Mono, but they are passed with a '-' charater instread of a '/'. Here are he results:

-----------------------------------------------------------------------------
Running Mono binary:
ArrayList strings test.............890 ms
StringBuilder test.................1046 ms
Integer & Floating ADD.............2015 ms
Exception test.....................859 ms
Reflection and recursion...........3890 ms
-----------------------------------------------------------------------------
Running Framework binary:
ArrayList strings test.............921 ms
StringBuilder test.................1078 ms
Integer & Floating ADD.............984 ms
Exception test.....................812 ms
Reflection and recursion...........3875 ms
-----------------------------------------------------------------------------

With speed no longer an issue, the only important thing that is now missing from Mono is Windows.Forms, but this is under heavy development and I'm sure we are going to see it in future releases.

After doing these tests and viewing the results, I only have two gthings to say:

1.        Thank you Microsoft for .NET and C#.

2.        Thank you Mono for true cross-platform development (almost there).

 

Print | posted on Sunday, August 28, 2005 6:14 PM |

Feedback

Gravatar

# re: Mono vs. .NET Performance Test

These are really great news, thanks for all these useful numbers.

I'm totally with you, we're almost there on cross-platform development, and I am totally greatful about it as a developer.
My only drawback is how fast C# and the Framework change, making it really difficult for the Mono Project to keep up. I would really, really like we couldn't have to go back a version to make sure it is cross-platform compatible, but I'm sure that with time they will both stabilize and Mono will be able to reach the same feature set as in the most current version of the Framework.
7/14/2006 7:54 PM | Murven
Gravatar

# re: Mono vs. .NET Performance Test

Great test; any possibility specifying what version of Mono you used, and of rerunning with the latest if applicable?
1/20/2008 1:55 PM | Jorgen
Gravatar

# re: Mono vs. .NET Performance Test

thanks 4 your test.

but, I've a question, is Mono fully-compatible with .NET?
like running web services on linux?
2/27/2008 2:25 PM | M.S. Babaei
Gravatar

# re: Mono vs. .NET Performance Test

I just found this article, hope it is helpfull. http://codicesoftware.blogspot.com/2007/11/c-mono-performance.html
4/1/2008 9:44 PM | VietNam Computer Jobs
Gravatar

# re: Mono vs. .NET Performance Test

This tests have been taken 3 years ago, what about these days?
5/16/2008 12:29 PM | Justin
Gravatar

# re: Mono vs. .NET Performance Test

I'm curious too.

Anyone willing to do some benchmarking?
6/6/2008 2:16 PM | rei
Gravatar

# re: Mono vs. .NET Performance Test

Not that hard to do, you know. I just dumped the test into a file and compiled a .net 2.0 binary (csc test.cs) and a mono binary (mcs test.cs -out:test-mono.exe):

.NET running .NET-compiled EXE (.\test.exe):
ArrayList strings test.............421 ms
StringBuilder test.................640 ms
Integer & Floating ADD.............1531 ms
Exception test.....................2593 ms
Reflection and recursion...........3984 ms

.NET running mono-compiled EXE (.\test-mono.exe):
ArrayList strings test.............703 ms
StringBuilder test.................625 ms
Integer & Floating ADD.............1531 ms
Exception test.....................656 ms
Reflection and recursion...........2265 ms

mono running .NET-compiled exe (mono test.exe):
ArrayList strings test.............469 ms
StringBuilder test.................859 ms
Integer & Floating ADD.............4547 ms
Exception test.....................422 ms
Reflection and recursion...........3703 ms

mono running mono-compiled exe (mono test-mono.exe):
ArrayList strings test.............469 ms
StringBuilder test.................828 ms
Integer & Floating ADD.............4547 ms
Exception test.....................438 ms
Reflection and recursion...........3625 ms

This is run on a 2GHz core 2 duo centrino.
10/7/2008 5:28 PM | Seth
Gravatar

# re: Mono vs. .NET Performance Test

Should have mentioned that this was compiled under mono 2.0 (ftp://ftp.novell.com/pub/mono/archive/2.0/windows-installer/5/mono-2.0-gtksharp-2.10.4-win32-5.exe) :D
10/7/2008 5:32 PM | Seth
Gravatar

# re: Mono vs. .NET Performance Test

good results
11/22/2008 2:46 AM | trendbender
Gravatar

# re: Mono vs. .NET Performance Test

Hi. There is no true test. Tasks should be a bit larger to get real results, at least 5 minutes but not 1-4 seconds.
btw.. on my PC

.NET running .NET-compiled EXE (.\test.exe):
ArrayList strings test.............328 ms
StringBuilder test.................531 ms
Integer & Floating ADD.............812 ms
Exception test.....................1900 ms
Reflection and recursion...........3593 ms

mono running mono-compiled exe (mono test-mono.exe):
ArrayList strings test.............382 ms
StringBuilder test.................710 ms
Integer & Floating ADD.............6147 ms
Exception test.....................339 ms
Reflection and recursion...........2109 ms

But results is pretty nice, сonsidering the fact that my mono (openSuze) is running on VmWare
1/21/2009 1:28 PM | Volatile
Gravatar

# re: Mono vs. .NET Performance Test

Hi,

I currently work on search trees for metric data written in C# with VS 2008.

Some tests with 2d-Points runs on .Net in 20 s,
running the .Net compiled exe takes almost 80 s on mono.

This can't all just depend on the Int and float-add because the tree tries to minimize distance computations. Mono is running natively in Win Vista 64.
4/22/2009 5:05 AM | G
Gravatar

# re: Mono vs. .NET Performance Test

ArrayList strings test.............332 ms
StringBuilder test.................676 ms
Integer & Floating ADD.............4223 ms
Exception test.....................358 ms
Reflection and recursion...........2581 ms

DELL Precision M4300 - Core2Duo 2.0 GHz, RAM 2GB / 677MHz
5/3/2009 1:35 AM | xljan
Gravatar

# re: Mono vs. .NET Performance Test

Wow, this is pretty impressive, nothing much left indeed to make it really rock!
6/17/2009 9:21 PM | clabesse
Gravatar

# re: Mono vs. .NET Performance Test

The System.Xml still has some not compatibal with the W3C or .NET. and my application's running time. Mono's Time = .Net's Time * 5.

It's still a problem. I'm using Mono 4.2.
6/19/2009 4:49 AM | GuoHui Chen
Gravatar

# re: Mono vs. .NET Performance Test

Sorry for my last comment, I test the mono under VMWare Player. when I running the mono in windows. Mono's Time = .Net's Time * 2
7/3/2009 8:51 PM | GuoHui Chen
Gravatar

# re: Mono vs. .NET Performance Test

Speed is one of the most important things to me. I wouldn't be able to run an application with Mono because of this.
1/16/2010 11:26 PM | Speed Dating Chicago
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: