I have some code which runs on Visual Studio (MSVC compiler) with an average speed per message of 127 CPU cycles. I ported it over to Linux (Mint 16), Netbeans 7.4 and GCC 4.8. The code is C++ standard compliant.
The only changes I had to make was to replace __rdtsc()
with an inline GCC version. To run the code I changed Netbeans to Release mode, went in to the properties and changed the setting so that this was a "Performance Release". I then click on the green arrow and the program is taking on average 229 CPU cycles per message- nearly double the MSVC time.
Am I running Netbeans release mode correctly? I know on Visual Studio you have to press ctrl + f5 for a proper performance release. I werent sure if there was an equivalent mistake to make using Netbeans? I was expecting the code to be faster on Linux!
The code doesn't use any containers except for raw arrays.
Timing:
Windows I used:
unsigned long long start = __rdtsc();
//Code
unsigned long long finish = __rdtsc();
Linux, same as above except I used:
#if defined(__i386__)
static __inline__ unsigned long long rdtsc(void)
{
unsigned long long int x;
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
return x;
}
#elif defined(__x86_64__)
static __inline__ unsigned long long rdtsc(void)
{
unsigned hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
}
#endif
Which I got from this SO answer: https://stackoverflow.com/a/9887899/997112