I've decided to switch from Flash to some newer technology. I've found a project on github (https://github.com/Danakh/oldies-bc-as3converter) to convert my actionscript to C#, so I give a try to Unity and MonoGame (both using C# and are currently under active development).

I found MonoGame far more easy to use, as it only requires Visual Studio. But even with Xamarin, it target fewer platforms than Unity. Unity on the other hand does not integrate visual studio very well. But I think the 5.1 version broke the UnityVS plugin. The main issue is that I was astonished by how bad my library perform in Unity. Performances was on part with actionscript (on windows) while MonoGame runs the code 4 times faster.

So I make a little test computing Fibonacci sequence:

  • Using linear and recursive algorithm
  • Using plain int, struct containing an int, and class containing an int
  • Computing sequence of 20, 30 and 40 elements (with some loop around the linear test to have good results)

  • Of course, I do not use MonoGame there, it is a classical Visual Studio project. The code is in the linked file as the bottom. Here are the results:

    testVisual StudioUnity
    linear171 ms261 ms400 ms215 ms328 ms446 ms
    recursive171 ms266 ms1045 ms215 ms336 ms1497 ms
    linear + struct372 ms530 ms1455 ms424 ms663 ms1957 ms
    recursive + struct372 ms535 ms2065 ms425 ms676 ms3530 ms
    linear + class564 ms830 ms2498 ms1172 ms1538 ms4533 ms
    recursive + class564 ms842 ms4091 ms1173 ms1707 ms24775 ms

    There are several interesting things to notice :
  • both seems to remove recursivity for low number (20 / 30)
  • int is better than struct which is better than class. I was expecting struct to be as int or as class, but not in the middle like that.
  • Unity deeply fail on a large number of memory allocation. The number of function calls seems to be an issue as well, but not as bad

  • My library use a lot of small object with a lot of function calls ...