[Mono-list] Evolutionary Algorithms with Mono slower than with .Net ?

Daniel Hofmann daniel at hofmannmail.ath.cx
Fri Mar 16 11:41:41 EDT 2007


Hi everyone,

I'm about to take part in a student project about evolutionary
algorithms. We really would like to do all of this in C# having it
hopefully run with .Net and Mono in the end. We've written a prototype,
that does run under both those platforms and were running some tests
with this prototype. I've included some results of these tests at the
end of the mail. The prototype implements the Travelling Salesman
problem, i.e. "For a given set of points and the distances between them
find the shortest possible route, that visits all of the points once".
Implementing the evolutionary principle the prototype "breeds" a
"population" of such routes. After this population is initialized it
endlessly loops (one loop is called a generation), where all routes are
evaluated (the shorter, the better), based on the results some are
chosen to "produce" the next generation, which is accomplished by
recombining them in some way to get (hopefully better) "children", which
are used in the next loop.

Our test results showed a big discrepancy in performance between Mono
and .Net. .Net reaches generation 5000 after about 9 secs, whereas Mono
needs about 23 seconds.

Here are some things that might give you a better idea of what exactly I
did:

- Every route is an array of 52 integers. (each integer is just the
number of a position)
- The arrays are stored inside a System.Collections.Generic.List<>.
- There are many calls of System.Random.Next() involved (for
initialization, and to decide, who survives or reproduces)
- The timer results are always in the same range (+/-1sec)
- I did use the exact same assemblies on both platforms
- They were compiled on linux with gmcs from the new 1.2.3.1 release
- I also used this release for the mono runs.
- During the loop, there's no I/O involved (except printing to stdout)
- of course the windows/linux runs took place on the same computer (amd
athlon xp 1,8Ghz)
- on my laptop (pentium M) the discrepancy was similar, but not that bad
for mono
- The whole thing doesn't consume much memory (no virtual memory was used)
- Using Mono on windows didn't make any difference to using it on linux.
- The loop is in a different assembly, than the operations, that are
called from inside (might be a reason for the issue ?)

My colleagues don't want to start a project, that performs that poor on
the platform where it probably will mostly be used in the end.

That's why I really would appreciate any clue, that could explain this
discrepancy and still is an argument why we could use the CLI anyway. I
would continue to use Mono despite of this problem, but unfortunately
I'm not the only one to decide.

I realize, that the primary goal of Mono isn't performance, but
compatibility, but I wouldn't have thought, that such an algorithm, that
consists of the stupid iteration of the same loop, calling the same
methods over and over again, could leave so much room for optimization.


Sorry, for that much text in one mail :-$
I hope, that at least someone has made it this far..

Many thanks in advance,
Daniel

----------------------------------------------------------------------------
----------------------------------------------------------------------------

The test results, which surely shouldn't be used for general performance
conclusions regarding Mono vs .Net:

The program prints out such a block of five rows to stdout every 100
generations. Of course the generations start at 0 as well as the timer,
but I've only included the three blocks around generation 5000.

-------------------------------------------------
mono without any commandline arguments

Generation:      4900
Size of population:    79
Time since beginning:       0:0:25
average length:        8144,98528708903
shortest length:    8086,32284136887

Generation:      5000
Size of population:    71
Time since beginning:       0:0:25
average length:        8166,81782827583
shortest length:    8086,61915071641

Generation:      5100
Size of population:    73
Time since beginning:       0:0:26
average length:        8188,03206589651
shortest length:    8086,32284136887

-------------------------------------------------
mono --optimize=all

Generation:      4900
Size of population:    79
Time since beginning:       0:0:23
average length:        12381,2668583939
shortest length:    8401,50496691767

Generation:      5000
Size of population:    78
Time since beginning:       0:0:23
average length:        11350,3764229265
shortest length:    8401,50496691767

Generation:      5100
Size of population:    74
Time since beginning:       0:0:24
average length:        12367,2536411724
shortest length:    8358,44085439801

-------------------------------------------------
mono --debug

Generation:      4900
Size of population:    75
Time since beginning:       0:0:24
average length:        9014,63922380426
shortest length:    7880,38877430051

Generation:      5000
Size of population:    79
Time since beginning:       0:0:25
average length:        8205,89025321323
shortest length:    7861,06580114686

Generation:      5100
Size of population:    77
Time since beginning:       0:0:25
average length:        8182,20947790275
shortest length:    7856,96027108485
-------------------------------------------------
.NET 2.0 WinXP without any special options
(at least none that I'm aware of)

Generation:      4900
Size of population:    78
Time since beginning:       0:0:9
average length:        11162,8345961251
shortest length:    8043,17285789566

Generation:      5000
Size of population:    74
Time since beginning:       0:0:9
average length:        11637,4209382803
shortest length:    8043,17285789566

Generation:      5100
Size of population:    77
Time since beginning:       0:0:9
average length:        12653,1112069315
shortest length:    8043,17285789566


More information about the Mono-list mailing list