2009-01-21

Mono 2.2

Recently Mono 2.2 was released. It has a bunch of new stuff, one of them is: SIMD (Single Instruction, Multiple Data) support in Mono.

Miguel de Icaza has a blog entry where he describes the new SIMD support in Mono. He has ported to C# a C++ application, to illustrate the new SIMD stuff, and then he compares the results, the C++ program was rather slow. I had a look at the source code an I've seen that the C++ program was compiled in debug mode.

I've decided to make a few tests for myself. I've used MinGW 4.3.2 and Visual Studio 2005, the tests where run on my Intel Mobile Core 2 Duo T7500.

Here are the results (in seconds):



The parameters for the above results were:



Mono is not quite there yet (at least on Windows).

I had to change the timing code for the C++ code, glib::GTimer is not a very good option on Windows. I've used the high-resolution performance counter, the code is presented below:


#ifndef PERFTIMER_H
#define PERFTIMER_H

#include <windows.h>
#include <string>

#include <iostream>
#include <iomanip>
#include <sstream>

class PerfTimer
{
     LARGE_INTEGER start_;

     LARGE_INTEGER stop_;
     LARGE_INTEGER freq_;
   public:
    
     PerfTimer()
     {
       QueryPerformanceFrequency(&freq_);
     }

    
     void Start()
     {
       QueryPerformanceCounter(&start_);
     }
    
     void Stop()

     {
       QueryPerformanceCounter(&stop_);
     }
    
     std::string ToString()
     {
       const int precision = 10000000;

       unsigned long time = static_cast<unsigned long>(
     (stop_.QuadPart - start_.QuadPart) * precision /
     freq_.QuadPart);
      
       std::ostringstream os;

       os << std::setfill('0');
       os << std::setw(2) << time / precision / 3600 << ":";
       os << std::setw(2) << time / precision % 3600 / 60 << ":";

       os << std::setw(2) << time / precision % 60 << ".";
       os << std::setw(7) << time % precision;
       os << std::setfill(' ');

      
       return os.str();
     }
};

#if 0
int main()
{
   PerfTimer timer;
   timer.Start();

   Sleep(1250);
   timer.Stop();
  
   std::cout << "Time: " << timer.ToString() << std::endl;
  
   return 0;
}

#endif

#endif // PERFTIMER_H




There are a few things I would like to point out about the Mono 2.2 Windows installer.

1. The executable is not digitally signed by Novell.



2. The graphics are hideous, 16 colors dithering? why? Is anybody in their right mind running Windows in 16 colors?


5 comments:

Florin said...

There is a mistake in your timing code; you print the hours, then you convert the whole time in minutes, even the one that was already printed in hours, and so on. You should use the remainders.

I would post some code, but I am tired, the dog ate my compiler and so on.

Cristian said...

Thanks, I've updated the code.

Stifu said...

"The graphics are hideous, 16 colors dithering? why? Is anybody in their right mind running Windows in 16 colors?"

For the record, I've filed a bug about that not long ago: https://bugzilla.novell.com/show_bug.cgi?id=462796

Anonymous said...

Thanks for taking the time to do a fair comparison between Mono and C++ SIMD. I don't think that Miguel was trying to spread FUD by posting that bar graph, but it's been picked up by other sources as a reason to say that Mono is faster than C++. Comparing apples to oranges never does anyone any good. Our numbers may be getting fewer and fewer, but articles such as this show that C++ still delivers where it counts.

Anonymous said...

Yes, thanks for running this in a more sane environment. As soon as I saw Miguel's chart stating that he *didn't* use any fancy compiler optimization flags for C++, my nostrils started flaring. Surely, if someone is doing game development in C++, they are going to put a few hours into learning their compiler settings as well!