Board index » delphi » Delphi VS C++ Builder speed comparison (general)
dMessett
![]() Delphi Developer |
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 |