[Mono-list] Poor Mono performance
Nigel Delaney
nigel.delaney at outlook.com
Mon Mar 11 20:08:29 UTC 2013
I played around a bit with this and also noticed a very substantial MS
versus MONO difference, some notes on this:
*The biggest performance difference here is not the mono vs. .NET but rather
how the program is written. Right now the bulk of the code on both Mono and
.NET is spent on the do-while loop, and this is a HUGE waste of repeated
method calls. Every increment of an array element involves a method call,
and I could drop the runtime of the program about two orders of magnitude by
writing a different advance function as shown at the end of this email.
That function can't really be inlined properly by either MS or mono, and the
runtime goes from about 1.9 seconds on my machine to .01 seconds with this
change, though the code does the same thing. If the code you are writing in
practice does look like this, it can be improved a lot by having the called
method not return until a condition is met, rather than returning, checking
the condition, and calling again.
*Strangely, after the code is changed to accommodate this, mono and MS on
my test machine appear to have an unbelievably large difference in speed.
This appears to be "fake" differences due to how the startime variable is
set and nothing to do with the execution speed of the main method. If
starttime is reset inside the method by setting it again after printing it
to the console, the performance difference disappears. There still appears
to be a <2X mono performance penalty when mono is used with a List type, but
with an array for the counters, I seem to get the same results on mono and
ms.
If you try the program below, I would be interested to know if the speed was
equivalent on your machine for mono and .net. One problem is that it is so
fast on both now that it is hard to compare.
-Nigel
PS It would still be nice to have a way to view the emitted assembly code on
windows in mono so could compare with the ms clr.
//improved program
using System;
using System.Collections.Generic;
namespace SpeedTest
{
class SpeedTest
{
static void Main(string[] args)
{
var totals = new int[] { 10, 10, 100, 100, 100 };
var counters = new int[] { 0, 0, 0, 0, 0 }; ;
int counter = 0;
//Variable needs to be set again after printing, otherwise
result is wrong
var startTime = DateTime.Now;
Console.WriteLine("START TIME: {0}", startTime.ToString());
startTime = DateTime.Now;
int total = 1;
for(int i=0;i<totals.Length;i++) {
total*=totals[i];
}
Console.WriteLine("Total = {0}", total);
Console.WriteLine("Dif= {0}", (DateTime.Now -
startTime).ToString());
Advance(counters,totals);
//just to make sure it doesn't avoid the advance method call
Console.WriteLine(counters[2].ToString());
var endTime = DateTime.Now;
Console.WriteLine();
Console.WriteLine("END TIME: {0}", endTime.ToString());
Console.WriteLine("RUN TIME: {0}", (endTime -
startTime).ToString());
Console.ReadLine();
}
static void Advance(int[] current, int[] total)
{
for (int index = current.Length - 1; index >= 0; --index)
{
while(current[index] != (total[index] - 1))
{
++current[index];
}
}
}
}
}
________________________________________
From: mono-list-bounces at lists.ximian.com
[mono-list-bounces at lists.ximian.com] On Behalf Of Robert Jordan
[robertj at gmx.net]
Sent: Monday, March 11, 2013 2:15 PM
To: Mono-list at lists.ximian.com
Subject: Re: [Mono-list] Poor Mono performance
On 11.03.2013 17:19, Olajos, Imre wrote:
> Is there anything I can do that would bring their relative performance
> difference closer to each other (e.g. below 20-25%)?
So you didn't find the well-hidden "--make-me-as-fast-as-ms"
switch, did you? :)
You're comparing MS' 64-bit runtime with a 32-bit Mono w/out LLVM support
and with a pretty slow GC (under Windows).
Since Windows isn't Mono's prime-time OS, you may want to try under 64-bit
Linux (where you can have LLVM and alternative GCs), identify bottlenecks
and file bugs with appropriate test cases.
Robert
_______________________________________________
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