I have played with Parallel Extensions and noticed to my surprise that
executable compiled for x64 runs slower than compiled for x86:
private static double HeavyMath( int I )
{
double D1 = Math.Sqrt( I ) * Math.Pow( I, Math.PI ) * Math.Pow( I, 1 /
Math.E );
double D2 = Math.Sqrt( I ) / Math.Pow( I, Math.PI ) / Math.Pow( I, 1 /
Math.E );
return D1 / D2 + D2 / D1;
}
private static double Sequential( int N )
{
double R = 0;
for ( int I = 1; I <= N; I++ )
{
double D = HeavyMath( I );
R += D;
}
return R;
}
private static object lockThis = new object();
private static double Parallel1( int N )
{
double R = 0;
Parallel.For( 1, N + 1,
I =>
{
double D = HeavyMath( I );
lock ( lockThis )
{
R += D;
}
}
);
return R;
}
private static void CallMethod( Func<int, doubleM )
{
Stopwatch SW;
double D;
const int N = 20000000;
SW = Stopwatch.StartNew();
D = M( N );
SW.Stop();
Console.WriteLine( "{0}: {1:F0}", M.Method.Name, D );
Console.WriteLine( "{0}: {1} ms", M.Method.Name,
SW.ElapsedMilliseconds );
}
static void Main( string[] args )
{
CallMethod( Sequential );
CallMethod( Parallel1 );
}
Sequential method takes ~11,2 sec if compiled for x64, but only ~9,8 sec if
compiled for x86.
Parallel1 method takes ~7,1 sec if compiled for x64, but only ~6,7 sec if
compiled for x86.
Environment is VS2008, Vista Ultimate 64-bit, Core 2 Duo 2.40 GHz.
Are such times result from use of double arithmetic ?
Or what else ?
Oleg Subachev