[Mono-list] mono performance, 20x differential with Java (what am i doing wrong)

Jonathan Shore jonathan.shore at gmail.com
Fri Jan 29 09:50:21 EST 2010


Stifu,  I am not (or should not) be creating any garbage during the test (except the array to be later thrown away once).   The test is simply testing operations around reading and writing to any array.   

Now I know that Java and C# both use guards to ensure that array access is bounded.   In the case of java it is able to avoid the guards via range analysis.   With C# and unsafe, this should not even be a factor.  I am then perplexed as to what mono is doing.   What operations above array access and basic arithmetic are being done such that it is so much slower?

Is there a command line tool I could use to see what code was emitted?   Anyone have experience with LLVM with this sort of test?   (I've not been successful in compiling glib and therefore mono with that enabled)?


On Jan 29, 2010, at 9:28 AM, Stifu wrote:

> 
> I could be wrong, but intensive operations like these may run faster with the
> upcoming new garbage collector (coming in Mono 2.8).
> I don't know if the new GC is currently stable enough for you to try it.
> 
> 
> Jonathan Shore wrote:
>> 
>> Diego,  Thanks for your suggestions.   I adjusted to use an unsafe
>> declaration around test1(), but get the same performance results.    I am
>> wondering whether there is some optimisation mode I need to enable in the
>> mono VM.    Anyone have an idea?
>> 
>> I did:
>> 
>> 	mcs -optimize -unsafe *.cs
>> 	mono ArrayTest.exe 1000
>> 
>> Result: 
>> starting performance test on 1000 iterations
>> ending performance test on 1000 iterations, time: 16:919
>> 
>> On Java VM this is < 1 second.
>> 
>> Are there some flags I can use on the mono VM to speed this up?    Would
>> the LLVM version do significantly better?
>> 
>> Jonathan
>> 
>> On Jan 28, 2010, at 10:33 PM, Diego Frata wrote:
>> 
>>> Hello Jonathan,
>>> 
>>> I'm working on a computer that has a Intel Core 2 Duo CPU T5250 1.5 GHz
>>> (way slower than yours). I've tried the code below on .NET 4 Beta 2
>>> (shame on me, my other computer died some days ago and I didn't install
>>> Mono) and I got worst results than you at a very first moment.
>>> 
>>> My first setup was the default one for VS2010. Release x86
>>> 
>>> starting performance test on 1000 iterations
>>> ending performance test on 1000 iterations, time: 43:733
>>> result: 2729781599,99818
>>> 
>>> Oops, I'm running a 64 bit OS, so I've compiled my application again
>>> targeting Release x64
>>> 
>>> starting performance test on 1000 iterations
>>> ending performance test on 1000 iterations, time: 10:813
>>> result: 2729781599,99818
>>> 
>>> That's a lot better, but I can speed up things a little bit introducing
>>> some unsafeness into the code:
>>> 
>>>        public unsafe static double test1(double* vec, int size)
>>>        {
>>>            double sum = 0;
>>>            for (int i = 8; i < size; i++)
>>>            {
>>>                vec[i] = 2 * vec[i] - vec[i - 1];
>>>                for (int j = 1; j < 8; j++)
>>>                    sum += 1.3 * vec[j - 1];
>>>            }
>>> 
>>>            return sum;
>>>        }
>>> 
>>>        public static void Main(string[] argv)
>>>        {
>>>            int iterations = argv.Length > 0 ? int.Parse(argv[0]) : 1000;
>>> 
>>>            unsafe
>>>            {
>>>                int size = 100000;
>>>                double* vec = stackalloc double[size];
>>>                for (int i = 0; i < size; i++)
>>>                    vec[i] = i;
>>> 
>>>                DateTime Tstart = DateTime.Now;
>>>                Console.WriteLine("starting performance test on " +
>>> iterations + " iterations");
>>> 
>>>                double sum = 0;
>>> 
>>>                for (int i = 0; i < iterations; i++)
>>>                    sum += test1(vec, size);
>>> 
>>> 
>>>                DateTime Tend = DateTime.Now;
>>>                TimeSpan Tspan = Tend - Tstart;
>>>                Console.WriteLine("ending performance test on " +
>>> iterations + " iterations, time: " + Tspan.Seconds + ":" +
>>> Tspan.Milliseconds);
>>> 
>>>                Console.WriteLine("result: " + sum);
>>>                Console.Read();
>>>            }
>>>        }
>>> 
>>> 
>>> starting performance test on 1000 iterations
>>> ending performance test on 1000 iterations, time: 5:571
>>> result: 2729781599,99818
>>> 
>>> That's the best I could extract from a single threaded computation
>>> without changing your logic.
>>> 
>>> Try take a look at these things, maybe Mono is presenting the same
>>> behavior as .NET.
>>> 
>>> 
>>> Sorry if all this was unhelpful and off-topic ;)
>>> 
>>> Diego Frata
>>> diego.frata at gmail.com
>>> 
>>> 
>>> On Fri, Jan 29, 2010 at 12:00 AM, Jonathan Shore
>>> <jonathan.shore at gmail.com> wrote:
>>> Hi,
>>> 
>>> I'm quite familiar with both the .NET and Java development environments,
>>> but only recently have begun to experiment with mono, so forgive me if
>>> I'm not clued-in.   
>>> 
>>> I specialize in numerical work that often involves a lot large-scale
>>> array manipulation for linear algebra, timeseries, etc.    My main
>>> production platforms are OSX and Linux.   I've been doing most of my work
>>> on the JVM over the past few years, though spent a couple of years with
>>> .NET when it was pre-release / pre-1.0.  
>>> 
>>> My main interest is in Ocaml, particularly the F# variant as the basis
>>> for my numerical work.
>>> 
>>> One of the first things I do when considering a platform is run
>>> benchmarks, as performance is critical for what I do.    Starting with C#
>>> I wrote a test to gauge the array-access overhead associated with the
>>> platform.  Without knowing how to tweak the mono runtime to turn on any
>>> particular optimisations, the results were quite poor for this specific
>>> test (see code at the end of this posting).
>>> 
>>> 
>>> The test on my MacPro 2.6 Ghz / Snow Leopard with mono 2.6.1 gave the
>>> result of:
>>> 
>>> 	16 sec, 130 ms for 1000 iterations
>>> 
>>> the same code, modified just for IO, etc on the Java VM (without -server) 
>>> gave a runtime of:
>>> 
>>> 	 0 sec, 831 ms
>>> 
>>> changing the # of iterations to higher amounts did nothing to improve the
>>> ratio.   Java is 20x faster in this benchmark.
>>> 
>>> I could not find any documentation concerning settings for the -optimize
>>> flag on the mono VM, so perhaps there is a setting I should be using.   
>>> 
>>> Secondly, I saw the posting concerning the optional use of LLVM.  I have
>>> not been able to build mono on OSX as am having problems building glib. 
>>> I'm wondering whether anyone has a packaged up version of glib or better
>>> a packaged up version of mono with LLVM enabled.
>>> 
>>> I have heard only good things about LLVM performance, so hoping that this
>>> will help address this gap.   Hopefully I am doing something wrong here
>>> and the performance is much closer.   Test code below ...
>>> 
>>> regards
>>> 
>>> Jonathan
>>> --
>>> http://tr8dr.wordpress.com/
>>> 
>>> 
>>> using System;
>>> 
>>> namespace Performance
>>> {
>>> 
>>> 	public class ArrayTest
>>> 	{
>>> 		
>>> 		public static double test1 (double[] vec)
>>> 		{
>>> 			double sum = 0;
>>> 			for (int i = 8 ; i < vec.Length ; i++)
>>> 			{
>>> 				vec[i] = 2*vec[i] - vec[i-1];
>>> 				for (int j = 1 ; j < 8 ; j++)
>>> 					sum += 1.3 * vec[j-1];
>>> 			}
>>> 			
>>> 			return sum;
>>> 		}
>>> 
>>> 		public static void Main (string[] argv)
>>> 		{
>>> 			int iterations = argv.Length > 0 ? int.Parse(argv[0]) : 1000;
>>> 			
>>> 			double[] vec = new double[100000];
>>> 			for (int i = 0 ; i < vec.Length ; i++)
>>> 				vec[i] = i;
>>> 			
>>> 			DateTime Tstart = DateTime.Now;
>>> 			Console.WriteLine ("starting performance test on " + iterations + "
>>> iterations");
>>> 			
>>> 			double sum = 0;
>>> 			for (int i = 0 ; i < iterations ; i++)
>>> 				sum += test1 (vec);
>>> 			
>>> 			DateTime Tend = DateTime.Now;
>>> 			TimeSpan Tspan = Tend - Tstart;
>>> 			Console.WriteLine ("ending performance test on " + iterations + "
>>> iterations, time: " + Tspan.Seconds + ":" + Tspan.Milliseconds);
>>> 
>>> 			Console.WriteLine ("result: " + sum);
>>> 		}
>>> 	}
>>> }
>>> 
>>> 
>>> 
>>> 
>>> 
>>> _______________________________________________
>>> Mono-list maillist  -  Mono-list at lists.ximian.com
>>> http://lists.ximian.com/mailman/listinfo/mono-list
>>> 
>>> 
>> 
>> 
>> _______________________________________________
>> Mono-list maillist  -  Mono-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-list
>> 
>> 
> 
> -- 
> View this message in context: http://old.nabble.com/mono-performance%2C-20x-differential-with-Java-%28what-am-i-doing-wrong%29-tp27366241p27372716.html
> Sent from the Mono - General mailing list archive at Nabble.com.
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list



More information about the Mono-list mailing list