# [Mono-list] Performance benchmark

JCKodel jckodel at gmail.com
Fri Feb 26 15:53:08 EST 2010

```First of all, this is NOT a "native MS .net framework is better" e-mail.

I want to build a huge cross-platform system, and I'm a .net programmer
since, well, ever =) so making something in .net running on all major
platforms would be heaven for me =) (not really many good results with Adobe
AIR, RealBasic, Lazaro, etc.)

So, I run a very dumb and simple test to check out if there were some
performance issue with mono. I'm using the latest stable release on both
Windows and Linux machines (didn't tested on Mac yet) and I'm getting a 10x
slower results for mono =(

The tests are very simple, although the code itself is not well written
(that was made on purpose). I know I can do the math way better and using
some other constructs on strings that are waaaay faster than raw strings.
The point is to force the memory manipulation, type converters and float
point calculations.

So, am I doing something wrong (in the sense of mono configuration or
options), or there is any tips that I should be aware of to, at least, bring
this difference for, say, 2x slower?

The source code for test is simple:

First, some stupid Math calculations:

for (int ct = 0; ct < 1000000; ct++)
{
decimal d = Convert.ToDecimal(Math.Pow(ct, 4));
d = Convert.ToDecimal(Math.Sqrt(Convert.ToDouble(d)) * 4 *
Math.Atan(Convert.ToDouble(ct)));
}

Then some memory play with raw strings:

for (int ct = 0; ct < 100000; ct++)
{
string foo = "foo";

for (int x = 1; x < 10; x++)
{
foo += " " + x.ToString("X2") + foo;
}

string bar = foo;
foo += bar;
}

The results:

Each test was done 3 times in a row. The numbers are milliseconds (lower,
better):

This is the executable generated by MonoDevelop, in Release configuration,
running on a Windows 7 Console:

Math: 535
Strings: 2.038
Math: 530
Strings: 1.962
Math: 530
Strings: 1.963

Using the mono.exe running the same executable above:
Math: 6.875
String: 6.206
Math: 6.840
String: 6.114
Math: 6.857
String: 6.116

Running the same executable above using ./Benchmark.exe on a Ubuntu terminal
running on a VirtualBox VM (not quite sure which mono version I'm running on
this machine, anyway, is a VM and is running faster than mono.exe on native
Windows):

Math: 5,934
String: 6,915
Math: 6,034
String: 7,489
Math: 5,740
String: 6,731

Then I got the source-code and paste it on Visual Studio 2008 SP 1 (on
Release config) This alone gives me a slight performance boost on memory
manipulation:

Math: 588
String: 1.289
Math: 566
String: 1.320
Math: 702
String: 1.393

A final test, using NGEN on the above executable (a huge gain was not
expected anyway):

Math: 567
String: 1.255
Math: 563
String: 1.269
Math: 562
String: 1.263

Again: THIS IS NOT A FLAME MESSAGE! I'm not here to tell which OS is better
or with framework implementation is better!

I just really want to make a cross-platform project and I'm concerned with
the huge performance differences.

My intention is to figure out what is going on and what can I do to improve
my mono projects.

Best regards,
[]
J.C.Ködel
Senior Programmer - .net/Adobe Flex Platform
--
View this message in context: http://n4.nabble.com/Performance-benchmark-tp1571319p1571319.html
Sent from the Mono - General mailing list archive at Nabble.com.
```