Board index » delphi » Delphi VS C++ Builder speed comparison (general)

Delphi VS C++ Builder speed comparison (general)


2004-11-20 11:39:17 AM
delphi283
Greetings all. I have a generic question; That of which is faster at
typical graphics related built-in functions such as Polyline etc.
Builder, or Delphi? I tried these two scenarios, same machine, same
everything as far as both applications were concerned, and I was shocked
by the results:
procedure TColorTest.BtnSpeedClick(Sender: TObject);
var
iter,x,y : integer;
P : PByteArray;
begin
for iter:=0 to 255 do
begin
for y :=0 to 255 do //row axis of image
begin
P := TempBitmap.Scanline[y];
for x :=0 to 255 do //256 columns (of 3 bytes), start@0
begin
P[x*3] :=iter;
P[x*3+1] :=y;
P[x*3+2] :=x;
end;
end;
Image2.Canvas.Draw (0,0,TempBitmap);
Image2.refresh;
end;
end;
And in C++ Builder 5, I did this:
void __fastcall TfrmForged::btn1Click(TObject *Sender)
{
int iter,x,y;
Byte *P;
for (iter=0; iter<=1023; iter++)
{
for (y=0;y<256;y++)
{
P = (Byte *)Bitmap1->ScanLine[y];
for (x=0; x<256;x++)
{
(P[x*3]) = iter;
(P[(x*3)+1]) = y;
(P[(x*3)+2]) = x;
}
}
Image1->Canvas->Draw (0,0,Bitmap1);
Image1->Refresh();
}
}
Now I hope that I don't offend anyone by posting C++ stuff here, but I'm
using Borland products nonetheless :). Though my code may suck (as does
my machine by today's standards), what I sought to do was implement the
exact same coding (functionally) in both development environments given
identical circumstances, identical parameters, and using the same
library methods/functions. I am not aware of any dissimilarity as far
as the pointer usage in the C++ example that I show, but if there is
some low-level difference (in the C++ version which results in a speed
penalty), I'd like to be made aware of it. Perhaps versions are an
issue, but I bought both development packages on the same date. Anyway...
I timed the results (crudely), and was surprised that the Delphi
implementation was significantly faster! Delphi took ~6.9 seconds to do
its thing, but Builder took ~9.9 seconds. Now my finger on the
stopwatch (!) wasn't terribly accurate, but I ran both apps which use
these proceedings repeatedly, and I say with certainty that the Delphi
version was without question significantly faster (when I ran it on my
machine under identical circumstances, as there's always B/G stuff, but
I was careful to run tests under the same conditions to avoid errors in
judgment).
So, the short (perhaps technical, but unbiased) answer that I am looking
for, is "why" is the Delphi result faster than the C++ result given the
scenario that I have illustrated?
Thanks in advance for any insight,
dhm
 
 

Re:Delphi VS C++ Builder speed comparison (general)

Quote
for iter:=0 to 255 do
for (iter=0; iter<=1023; iter++)
It seems that the BCB code must execute 4x as much data?
Just for a more basic comparison that takes out a few compiler
optimisations, try this:
procedure TColorTest.BtnSpeedClick(Sender: TObject);
var
iter,x,y: integer;
P: PByte;
begin
for iter:=0 to 255 do
begin
for y :=0 to 255 do //row axis of image
begin
P := TempBitmap.Scanline[y];
for x :=0 to 255 do //256 columns (of 3 bytes), start@0
begin
P^ :=iter; inc(P);
P^ :=y; inc(P);
P^ :=x; inc(P);
end;
end;
Image2.Canvas.Draw (0,0,TempBitmap);
Image2.refresh;
end;
end;
For bare speed comparisons also take out the Image2 calls at the end,
because these might influence the results in very strange incomprehensible
ways. It might even be that the Scanline[] call already behaves differently
across Delphi and BCB, but not sure.
Kind regards,
Nils Haeck
www.simdesign.nl
"dMessett" <XXXX@XXXXX.COM>writes
Quote
Greetings all. I have a generic question; That of which is faster at
typical graphics related built-in functions such as Polyline etc.
Builder, or Delphi? I tried these two scenarios, same machine, same
everything as far as both applications were concerned, and I was shocked
by the results:

procedure TColorTest.BtnSpeedClick(Sender: TObject);
var
iter,x,y : integer;
P : PByteArray;
begin
for iter:=0 to 255 do
begin
for y :=0 to 255 do //row axis of image
begin
P := TempBitmap.Scanline[y];
for x :=0 to 255 do //256 columns (of 3 bytes), start@0
begin
P[x*3] :=iter;
P[x*3+1] :=y;
P[x*3+2] :=x;
end;
end;
Image2.Canvas.Draw (0,0,TempBitmap);
Image2.refresh;
end;
end;


And in C++ Builder 5, I did this:

void __fastcall TfrmForged::btn1Click(TObject *Sender)

{
int iter,x,y;
Byte *P;
for (iter=0; iter<=1023; iter++)
{
for (y=0;y<256;y++)
{
P = (Byte *)Bitmap1->ScanLine[y];
for (x=0; x<256;x++)
{
(P[x*3]) = iter;
(P[(x*3)+1]) = y;
(P[(x*3)+2]) = x;
}
}
Image1->Canvas->Draw (0,0,Bitmap1);
Image1->Refresh();
}
}


Now I hope that I don't offend anyone by posting C++ stuff here, but I'm
using Borland products nonetheless :). Though my code may suck (as does
my machine by today's standards), what I sought to do was implement the
exact same coding (functionally) in both development environments given
identical circumstances, identical parameters, and using the same
library methods/functions. I am not aware of any dissimilarity as far
as the pointer usage in the C++ example that I show, but if there is
some low-level difference (in the C++ version which results in a speed
penalty), I'd like to be made aware of it. Perhaps versions are an
issue, but I bought both development packages on the same date. Anyway...

I timed the results (crudely), and was surprised that the Delphi
implementation was significantly faster! Delphi took ~6.9 seconds to do
its thing, but Builder took ~9.9 seconds. Now my finger on the
stopwatch (!) wasn't terribly accurate, but I ran both apps which use
these proceedings repeatedly, and I say with certainty that the Delphi
version was without question significantly faster (when I ran it on my
machine under identical circumstances, as there's always B/G stuff, but
I was careful to run tests under the same conditions to avoid errors in
judgment).

So, the short (perhaps technical, but unbiased) answer that I am looking
for, is "why" is the Delphi result faster than the C++ result given the
scenario that I have illustrated?

Thanks in advance for any insight,
dhm
 

Re:Delphi VS C++ Builder speed comparison (general)

"dMessett" <XXXX@XXXXX.COM>wrote
Quote
I timed the results (crudely), and was surprised that the Delphi
implementation was significantly faster! Delphi took ~6.9 seconds to do
its thing, but Builder took ~9.9 seconds.
What Nils said. Besides, by posting benchmarks, for which I assume you
didn't get explicit written permission from Borland, you are violating your
Borland license agreements.
 

Re:Delphi VS C++ Builder speed comparison (general)

Nils Haeck writes:
It seems that the BCB code must execute 4x as much data?
DOH! My bad, I posted code which was subsequently modified (repeatedly)
before recompilation & testing. At the time of testing it performed
1024 iterations as did the Delphi example. The speed difference is as
stated in my original message.
Just for a more basic comparison that takes out a few compiler
optimisations, try this:
procedure TColorTest.BtnSpeedClick(Sender: TObject);
var
iter,x,y: integer;
P: PByte;
begin
for iter:=0 to 255 do
begin
for y :=0 to 255 do //row axis of image
begin
P := TempBitmap.Scanline[y];
for x :=0 to 255 do //256 columns (of 3 bytes), start@0
begin
P^ :=iter; inc(P);
P^ :=y; inc(P);
P^ :=x; inc(P);
end;
end;
Image2.Canvas.Draw (0,0,TempBitmap);
Image2.refresh;
end;
end;
I will try the pointer stuff as in your example and see if there is a
performance increase for the C++ version. I didn't study the resulting
Assembler code in both versions to compare the results, and assume that
the loop constructs are not really the issue (both compilers optimal),
rather the library functions/procedures/methods [scanline] themselves
differ somewhat, or these functions were coded with Delphi in mind, and
had to be tweeked for Builder (minor penalty).
I prefer using Delphi generally speaking (liking the verbose nature).
The difference in speed was merely a curiosity, but I am grateful for
your suggestion, and will try it to see the results.
Dustin
 

Re:Delphi VS C++ Builder speed comparison (general)

Marcus F. writes:
Quote
"dMessett" <XXXX@XXXXX.COM>wrote


>I timed the results (crudely), and was surprised that the Delphi
>implementation was significantly faster! Delphi took ~6.9 seconds to do
>its thing, but Builder took ~9.9 seconds.


What Nils said. Besides, by posting benchmarks, for which I assume you
didn't get explicit written permission from Borland, you are violating your
Borland license agreements.


Thankyou for pointing that out Marcus. License violation was not
something that I had considered. My (relative) benchmarks were crude,
and limited to specific (obsolete) hardware of a given configuration.
This is incomparable to other machines of dissimilar configurations both
hardware and software. My claim was not intended to undermine one
particular product, nor imply that the other was superior. I just
wanted to know the underlying difference between the two, such that
perhaps I could better utilize each.
Knowing 'exactly how it works' (unless it is proprietary) was all that I
was interested in. I apologize for any other iferences.
Dustin
 

Re:Delphi VS C++ Builder speed comparison (general)

oh come on!
Its not like he's quoting inside information here, or trying to sell a rival
product.
As long as it is in the realms of borlando, it can only be a good thing
(except that dott netty stuff). I have just written an article about how you
can mix and match between cpp builder and delphi to get the best performace
kick.. thats not violation, thats development - and one of the thing i love
about borland.
Jon Lennart Aasenden
"Marcus F." <XXXX@XXXXX.COM>writes
Quote
"dMessett" <XXXX@XXXXX.COM>wrote

>I timed the results (crudely), and was surprised that the Delphi
>implementation was significantly faster! Delphi took ~6.9 seconds to do
>its thing, but Builder took ~9.9 seconds.

What Nils said. Besides, by posting benchmarks, for which I assume you
didn't get explicit written permission from Borland, you are violating
your
Borland license agreements.