473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Why x64 app runs slower than x86 app ?

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
Jun 27 '08 #1
3 3419
Well, one thing that occurs is that you can never trust the first run
for performance - "fusion", JIT - other things all contribute heavily
the first time through an execution path, and it could be that the
64-bit fusion/JIT is slower (juts a guess).

I would try running it twice in succession (in the same process), and
only look at the second set of numbers (which should be smaller for both
64 and 32)... does this make it any better?

Marc
Jun 27 '08 #2
I would try running it twice in succession (in the same process), and only
look at the second set of numbers (which should be smaller for both 64 and
32)... does this make it any better?
Here are the results of the following Main method:

static void Main( string[] args )
{
CallMethod( Sequential );
CallMethod( Parallel1 );
CallMethod( Sequential );
CallMethod( Parallel1 );
CallMethod( Sequential );
CallMethod( Parallel1 );
CallMethod( Sequential );
CallMethod( Parallel1 );
}

x64:
Sequential: 11264 ms 11244 ms 11249 ms 11249 ms
Parallel1: 6985 ms 6851 ms 6861 ms 6862 ms

x86:
Sequential: 9870 ms 9861 ms 9865 ms 9859 ms
Parallel1: 6700 ms 6579 ms 6581 ms 6587 ms
Oleg Subachev
Jun 27 '08 #3
"Oleg Subachev" <ol**@urvb.ruwrote in message
news:u6***************@TK2MSFTNGP02.phx.gbl...
>I would try running it twice in succession (in the same process), and
only look at the second set of numbers (which should be smaller for both
64 and 32)... does this make it any better?

Here are the results of the following Main method:

static void Main( string[] args )
{
CallMethod( Sequential );
CallMethod( Parallel1 );
CallMethod( Sequential );
CallMethod( Parallel1 );
CallMethod( Sequential );
CallMethod( Parallel1 );
CallMethod( Sequential );
CallMethod( Parallel1 );
}

x64:
Sequential: 11264 ms 11244 ms 11249 ms 11249 ms
Parallel1: 6985 ms 6851 ms 6861 ms 6862 ms

x86:
Sequential: 9870 ms 9861 ms 9865 ms 9859 ms
Parallel1: 6700 ms 6579 ms 6581 ms 6587 ms
Oleg Subachev


First of all you should never assume that X64 code will run faster than X86
code, 64 bit comes at a price, but, here it is slower.
The reason for this is that the CLR is not optimized to take advantage of
the features available in the newest AMD and Intel multicore processors,
notably the Math.Pow function does not take advantage of the newest floating
point arithmetic unit available, the x64 clr uses xmm + x87 FPU for
Math.Pow, while x86 clr uses the x87 FPU. It looks like the X86 Math.Pow
function is better optimized than the 64-bit version, no big surprise here,
MS doesn't care that much about 64-bit .NET.
Willy.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: djbigpond | last post by:
I have a query I developed and optimised as well as possible before converting to a view. When running in query analyser the query runs in 15 to 18 seconds - which is acceptable. When...
1
by: Tim Dol | last post by:
I have inherited a VB6-SP5 program connecting to an Access 2000 database. I'm relatively new to VB/Access programming, so I may overlook something obvious. I'll try to explain the problem I can't...
15
by: Ingmar | last post by:
Simple comparison tests we have performed show that System.Math functions in C# are much slower than corresponding functions in C++. Extreme examples are System.Math.Exp() and System.Math.Tan(),...
4
by: Corgan | last post by:
I compiled the same code as release version in VC++ 7.0 and it runs about 4X slower. My program is doing a mathematical search where time is important... am I forced to stick with the older version...
2
by: C.H. | last post by:
Hello, I am writing to a .txt file. Lots of data, about 1.1MB. It only took less than a second for VB6 to do so, but it took VB.NET one minute!! I am using a simple fileopen and print. Does...
12
by: jimocz | last post by:
Did I do something wrong? I cross posted this on the dotnet development group -- sorry if it is a double posting but we are seriously considering going to c# and this could be a show stopper. ...
11
by: ThunderMusic | last post by:
Hi, I have a windows service that only loads a CSV file and import it's data using SqlBulkCopy in a newly created Sql Server 2005 table using 25000 rows batches. If I build the service in debug...
2
by: Harmony504 | last post by:
I recently upgraded my application from PHP4.4.2 to PHP5.2.5. I also use MySQL5. I am using the mysqli module because supposedly it is faster. I have tested the regular mysql module and found it...
4
by: =?Utf-8?B?Q1IgU3VwcG9ydA==?= | last post by:
Hi experts, We are trying to migrate from Visual Studio 6 (C++ project) on Windows 2000 to Visual Studio 2005 SP1 on Windows Vista but found that the migrated program runs slower in both OS. A...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.