I am testing raw performance in Xamarin. To do this I have a simple Prime number generator. Implemented in Obj-c Xcode it takes 9 seconds, but in C# on Xamarin it takes 78 seconds. If I run in the emulator it is 800ms v/s 1600ms. I am doing a release build, with Optimization etc. Is Xamarin just generally slower for raw code execution? My code is here...
// C# version
public static CalcResult Calc (int max)
{
CalcResult res;
int maxPrime = 0;
Stopwatch sw = new Stopwatch();
sw.Start ();
for (int i = 3; i < max; i += 2)
{
bool prime = true;
for (int j = 2; j < (i / 2) + 1; j++)
{
if ((i % j) == 0)
{
prime = false;
break;
}
}
if (prime)
{
maxPrime = i;
}
}
sw.Stop ();
res.elapsedMilliseconds = sw.ElapsedMilliseconds;
res.largestPrime = maxPrime;
return res;
}
// Obj-C code version
+(int)CalcPrime:(int) maxInt
{
int maxPrime = 0;
for (int i = 3; i < maxInt; i += 2)
{
bool prime = true;
for (int j = 2; j < (i / 2) + 1; j++)
{
if ((i % j) == 0)
{
prime = false;
break;
}
}
if (prime)
{
maxPrime = i;
}
}
return maxPrime;
}