Microsoft Visual C++ 6.0 compiler vs Borland C++ Builder 5 compiler speed optimization.

Microsoft Visual C++ 6.0 compiler vs Borland C++ Builder 5 compiler speed optimization.

Post by Alex » Wed, 29 Jun 2005 01:19:44


I know that this post should be in the Borland site (and it is) but I am
getting no luck there so I thought I'd ask here (don't laugh). We use both
Microsoft and Borland here (mostly MS but one project uses Borland C++
Builder 5). We have had many complaints from customers that parts of our
program run way too slow (our math calculations). So I made the following
test program:

double x, y, z, tot = 0.0;
for (int j = 0; j < 1000; ++j)
{
for (int k = 0; k < 1000000; ++k)
{
x = 2;
y = .5;
z = x * x / (y + 2);
tot += z;
}
}

Yes I know the code is totally inefficient. It IS suppose to be. I want the
compiler to work for me in this case. When I compile this in Borland debug
114 sec., in MS debug about 114, in Borland release (compiler
flags -O2, -O, -Ov, -OS, -ff) still about 114, MS 5 sec.. I couldn't believe
it. The problem is that the project IS in Borland, it has hundreds of
thousands of lines of calculations (in many many loops) and I'm stuck. It is
as if the loop optimization flag does not work (with no caculations, just
the loops and a counter, the time difference is still overwelming). I am
using the math coprocessor, I check. Have you heard of such time
differences? If so, have you heard how to improve such difference using the
Borland compiler? I feel that I must not be setting something correctly in
Borland but I don't know what. I have posted this in Borland newgroups too
but people just keep responding that the code is inefficient and I should
rewrite it in ASM. They are missing the point!!!! Any help would be greatly
appreciated. Thanks in advance. Alex
 
 
 

Microsoft Visual C++ 6.0 compiler vs Borland C++ Builder 5 compiler speed optimization.

Post by Walter Bri » Wed, 29 Jun 2005 01:56:39

In message < XXXX@XXXXX.COM > of Mon, 27 Jun 2005
12:19:44 in microsoft.public.vc.language, Alex < XXXX@XXXXX.COM > writes
Why did you not cross-post?


This is a bad benchmark because it can easily be optimised.
x = 2;
y = .5;
z = x * x / ( y + 2 ); // z = 0.4
tot += z; tot += 0.4;

for ( int k ... ) ... is equivalent to tot += 4E6;
The total thing is equivalent to tot = 4E9;
If you want to set up a benchmark, use functions - probably in different
compilation units.

If you have speed problems, profile the code and focus on the hot spots.
--
Walter Briscoe

 
 
 

Microsoft Visual C++ 6.0 compiler vs Borland C++ Builder 5 compiler speed optimization.

Post by Duane Hebe » Wed, 29 Jun 2005 04:23:04


<snip>
the
greatly

From what I can see advice was to
profile this and see where the actual bottleneck was and post that.
It was also suggested that you replace math.h with fastmath.h.

Having used both BCB6 and MSVC7.1, I would say that MSVC seems
quicker but I've never profiled it.

I wouldn't expect much in the way of support though as both BCB5
and MSVC6 are not current products.
 
 
 

Microsoft Visual C++ 6.0 compiler vs Borland C++ Builder 5 compiler speed optimization.

Post by David Came » Wed, 29 Jun 2005 18:55:49


the
believe
is
the
greatly

Hi Alex,
Like Walter says you need to put your code in functions and use less
constant expressions.
Also return a value from your functions, make calls to other functions etc

I tried wrapping your code in a funtion with no return value i.e.

void test()
{
double x, y, z, tot = 0.0;
for (int j = 0; j < 1000; ++j)
{
for (int k = 0; k < 1000000; ++k)
{
x = 2;
y = .5;
z = x * x / (y + 2);
tot += z;
}
}
}

VS2003 optemises this function (in release mode) to a single asm line:

ret 0

This is because the function doesn't return a value or alter any external
variables, or call any functions.

HTH,
Dave
 
 
 

Microsoft Visual C++ 6.0 compiler vs Borland C++ Builder 5 compiler speed optimization.

Post by Ali » Wed, 29 Jun 2005 19:59:42

Humm.. really interesting discussion here. So Alex Borland people are
not responding you with reasonable question. Its stange to see how big
difference is;-)

rewrite it in ASM

Nope thats not gonna work, though it will improve some performance
slightly.

Addition to Walter Briscoe post:
This is also same solution as above while living in C++ world.

Try to write inline function with this minimum code in C++,, i'm sure
this is also not the solution , To me it is some thing with Borlan
compiler.

double x, y, z, tot = 0.0;
for (int j = 0; j < 1000; ++j , )
for (int k = 0; k < 1000000; ++k , x = 2 , y = .5 , z = x * x / (y
+ 2), tot += z);

Have tried it wrapping this code in Macro?
 
 
 

Microsoft Visual C++ 6.0 compiler vs Borland C++ Builder 5 compiler speed optimization.

Post by Darko Mile » Tue, 05 Jul 2005 21:42:32


You are missing the point here. As I told you in the thread at Borland
newsgroups Borland compiler can not optimise this code as good as MSVC.
Period. Accept this as a fact. It is indeed known fact that this
compiler is not the finest option when it comes to math code.

In order to get some speed boost with Borland compiler you have 3 options:

1. Write asm code
2. Move math code to msvc dll and use that from your main code
3. Wait for new CBuilder to see if they fix the math optimisation.

Darko