posts - 4, comments - 54, 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).

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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
Gravatar

# re: Mono vs. .NET Performance Test

Straaaaange... My benchmark (using complex mathematical problems and memory manipulation (with raw strings)):

MonoDevelop Windows (running on console using .net 3.5):
Realizando cálculos em 1.000.000 itens... 535
Realizando operações com strings longas... 2.038
Realizando cálculos em 1.000.000 itens... 530
Realizando operações com strings longas... 1.962
Realizando cálculos em 1.000.000 itens... 530
Realizando operações com strings longas... 1.963

Using mono.exe on Windows:
Realizando cálculos em 1.000.000 itens... 6.875
Realizando operações com strings longas... 6.206
Realizando cálculos em 1.000.000 itens... 6.840
Realizando operações com strings longas... 6.114
Realizando cálculos em 1.000.000 itens... 6.857
Realizando operações com strings longas... 6.116

Using mono on Linux Ubuntu:
Realizando cálculos em 1.000.000 itens... 5,934
Realizando operações com strings longas... 6,915
Realizando cálculos em 1.000.000 itens... 6,034
Realizando operações com strings longas... 7,489
Realizando cálculos em 1.000.000 itens... 5,740
Realizando operações com strings longas... 6,731

Same source code, but on Visual Studio 2008:
Realizando cálculos em 1.000.000 itens... 588
Realizando operações com strings longas... 1.289
Realizando cálculos em 1.000.000 itens... 566
Realizando operações com strings longas... 1.320
Realizando cálculos em 1.000.000 itens... 702
Realizando operações com strings longas... 1.393

VS 2008 generated exe with NGEN (native executable):
Realizando cálculos em 1.000.000 itens... 567
Realizando operações com strings longas... 1.255
Realizando cálculos em 1.000.000 itens... 563
Realizando operações com strings longas... 1.269
Realizando cálculos em 1.000.000 itens... 562
Realizando operações com strings longas... 1.263

In those tests, mono is 10x slower than .net 3.5 SP 1 =(
2/26/2010 2:14 PM | JCKodel
Gravatar

# re: Mono vs. .NET Performance Test

ArrayList strings test.............280 ms
StringBuilder test.................405 ms
Integer & Floating ADD.............920 ms
Exception test.....................1762 ms
Reflection and recursion...........1887 ms

i7@3.5 | MonoDevelop 2.2 | Server 2008 R2

I'll try on ubuntu 10.04
5/21/2010 11:54 PM | Avlin
Gravatar

# re: Mono vs. .NET Performance Test

ArrayList strings test.............178 ms
StringBuilder test.................288 ms
Integer & Floating ADD.............2848 ms
Exception test.....................163 ms
Reflection and recursion...........789 ms

mono and .net seem to be completly differents, but mono on linux is better that .net on windows, except the integer/floating test.

same hardware/user on ubuntu 10.04

multipe tests give sames results
5/22/2010 12:13 AM | Avlin
Gravatar

# re: Mono vs. .NET Performance Test

if you are looking at startup speed, memory and CPU utilization on desktops, http://www.codeproject.com/KB/dotnet/RuntimePerformance.aspx might help since it is using the latest releases as of July 2010


7/14/2010 6:10 PM | JFK
Gravatar

# re: Mono vs. .NET Performance Test

I like your blog. I look forward to seeing it once. Keep up the good job.
8/13/2010 8:21 PM | Moroccan furniture
Gravatar

# re: Mono vs. .NET Performance Test

This was a useful post and I think it is rather easy to see from the other comments as well that this post is well written and useful. I bookmarked this blog a while ago because of the useful content and I am never being disappointed. Keep up the good work
8/28/2010 4:31 AM | meilleur placement
Gravatar

# re: Mono vs. .NET Performance Test

pffff your TEST DO NOT WORK.
it's STUCK after test2.
test 3 - infinite. no result.

.NET 4, VC# 2010
9/3/2010 12:54 PM | Namer
Gravatar

# re: Mono vs. .NET Performance Test

But, if Ctrl+F5 (not just F5). then Test is OK.
And anyway - code of test really dumb. and i even say - its not objective.
Measure of time is wrong after Test1. (think why yourself)
9/3/2010 1:15 PM | Namer
Gravatar

# re: Mono vs. .NET Performance Test

Your concepts were simple to understand that I wondered why I in no way looked at it prior to.
9/21/2010 2:09 AM | burning crusade cd key
Gravatar

# re: Mono vs. .NET Performance Test

Great posting in your blog make it continue. I really enjoyed your article.
9/27/2010 12:31 AM | Breeches
Gravatar

# re: Mono vs. .NET Performance Test

Even i am getting some problem. There is some code missing...
9/28/2010 6:41 PM | school grants for minorities
Gravatar

# re: Mono vs. .NET Performance Test

Very good quality and great to know this page. Thanks
10/7/2010 1:58 AM | interest rates calculator
Gravatar

# re: Mono vs. .NET Performance Test

Incroyable cette histoire, je ne croyais pas à ça, merci, et bravo pour ce blog. Je pense que retournerai sur ce site.
11/15/2010 4:16 AM | Degree
Gravatar

# re: Mono vs. .NET Performance Test

This is really great help. Vista is hard to handle and such tutorial are highly helpful
11/16/2010 2:26 AM | PigyBankpie
Gravatar

# re: Mono vs. .NET Performance Test

I would like to thank you for the efforts you've made in writing this put up. I am hoping the exact same very best function from you inside the future too. Actually your creative writing abilities has inspired me to begin my own BlogEngine weblog now. Truly the blogging is spreading its wings rapidly. Your write up is really a fine example of it.
11/16/2010 5:27 AM | Blog
Gravatar

# re: Mono vs. .NET Performance Test

A good test, it will improve our wit and also beneficial for our experience. I really appreciate to your article. Thanks a lots.
11/17/2010 12:44 AM | quick lime powder
Gravatar

# re: Mono vs. .NET Performance Test

A good blog and a blatant Article in the blog. Bank problem are common in these days some one have some problem towards the bank.
11/17/2010 1:46 AM | Blogger
Gravatar

# re: Mono vs. .NET Performance Test

Thank you for awesome guidelines. As for my opinion, your tips can be useful for university students who need it.
11/18/2010 3:39 AM | Education
Gravatar

# re: Mono vs. .NET Performance Test

It's really a marvelous article article about this test. Their coding is really very hard and so important to have a great experience.
11/30/2010 2:20 AM | guest house in rajasthan
Gravatar

# re: Mono vs. .NET Performance Test

You have posted a very nice article post in the blog. i really appreciate to meet to it. Thanks for sharing to it. i am so happy to read it and felling glad that i am get this marvelous stuff of information.
12/21/2010 2:00 AM | solid wood furniture
Gravatar

# re: Mono vs. .NET Performance Test

ya like the man said
12/21/2010 3:57 PM | Internet marketing
Gravatar

# re: Mono vs. .NET Performance Test

I am so proud that so pleasant writers give their creations in our world. In case I were the monarch of the monarchy, I would give the creator of this essay with gold
12/24/2010 6:03 AM | designer dresses
Gravatar

# re: Mono vs. .NET Performance Test

Thanks a lot for the post! In code we trust!
12/30/2010 10:52 AM | adipex
Gravatar

# re: Mono vs. .NET Performance Test

I have cross this exam, but i want to know the name of this coding author. Really this coding is really marvelous.
1/7/2011 11:57 PM | International schools in Bangalo
Gravatar

# re: Mono vs. .NET Performance Test

In our Xml related test app, .NET is quick than Mono.
I think the System.Xml should put more focus on!
1/11/2011 1:33 AM | GuoHui Chen
Gravatar

# re: Mono vs. .NET Performance Test

The coding use for this test is really great. I really like this. I want know the writer of this coding. Will you tell me.
1/21/2011 2:00 AM | Bedroom Furniture
Gravatar

# re: Mono vs. .NET Performance Test

I would like to thank you for the efforts you have made in writing this post.
1/26/2011 12:54 AM | cheap kid rock tickets
Gravatar

# re: Mono vs. .NET Performance Test

I can’t believe how much of this I just wasn’t aware of. Thank you for bringing more information to this topic for me. I’m truly grateful and really impressed.
I posted your blog to my face book group

1/28/2011 12:42 AM | International schools in Bangalo
Gravatar

# re: Mono vs. .NET Performance Test

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.
2/2/2011 4:01 AM | funny valentine poems
Gravatar

# re: Mono vs. .NET Performance Test

Well accounting and researched article! I aloof abstract article new from you, as I acquire never heard of this before. Wish I could find this site before early on. The content of this post is very helpful and I, certainly, will read the other posts
2/2/2011 11:56 PM | cheap stomp tickets
Gravatar

# re: Mono vs. .NET Performance Test

Speed Looks good on mono. is it possible to run in linux an desktop application developed for windows using .net 4.0.
3/20/2011 2:02 AM | Payday Loans Online
Gravatar

# re: Mono vs. .NET Performance Test

Really nice code of C#.
7/26/2011 12:25 AM | web design Hertfordshire
Gravatar

# re: Mono vs. .NET Performance Test

Have you ever thought about adding a little bit more than just your thoughts? I mean, what you say is important and everything. But its got no punch, no pop! Maybe if you added a pic or two, a video? You could have such a more powerful blog if you let people SEE what youre talking about instead of just reading it.
9/15/2011 6:32 AM | hotel in jodhpur
Gravatar

# re: Mono vs. .NET Performance Test


The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought youd have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention.

11/15/2011 4:26 AM | hvof
Gravatar

# re: Mono vs. .NET Performance Test

I prefer your website for numerous factors. Many thanks for your reporting and high-quality view
11/18/2011 6:57 AM | vacation packages
Gravatar

# re: Mono vs. .NET Performance Test

I have been searching for this quality blogs regarding this niche. Searching in Yahoo drove me here, I just found this kind of satisfactory readings i was looking for. I must bookmark this website to avoid missing it again.
12/14/2011 1:01 AM | spray guns
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: