Archived

This topic is now archived and is closed to further replies.

How fast is Borland delphi?

This topic is 5283 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How much speed can you sqeez out of Borland Delphi in 3d games? Can it be compared with Visual C++? Acctually, I wrote my first game in Delphi, but that was a some years ago in Delphi 3 and it sucked, but how is it now?

Share this post


Link to post
Share on other sites
I wouldn't think that there would be too much difference between Delphi and VC++. The only comparison I remember is Jake's Code Efficiency Challenge, though that's not 3d specific (computationally intensive stuff like finding prime numbers, etc.). It's getting old now - most entries are for VC6 and Delphi 5. The results for the challenges put VC6 and Delphi 5 at the same speed and I seem to recall that Delphi 5 entries won one or two challenges.

As long as you know a little bit about how to optimize Delphi code then the speed should be just fine. The underlying computation won't be significantly faster or slower and most of your bottleneck will be from the 3d card itself. I would be surprised if you didn't have more than enough grunt from a Delphi game to do what you need. Hell, you could always dip into asm for your bottlenecks.

Plus, Delphi has some kick-ass 3d engines such as GLScene, a3d and GLXtreem.

I think that you'd be best asking Eric Grange or Tom Nuydens about this, since they have a heap of experience with 3d in Delphi. More to the point, though -- don't worry about performance yet. It's likely that the bottlenecks will be in small, specific places in your code. You should choose a language based on how productive you think you will be , other factors being roughly equal. If you think that you will be productive in Delphi then use it, else use something else.

[edited by - Alimonster on June 5, 2003 4:38:56 AM]

Share this post


Link to post
Share on other sites
Thank you! It''s good to know such things =)

Even though I think I stick with coding 3D in VC++ I think it''s really good that other languages than C++ can take a fight with c++ specially a "fun" language like Delphi(Pascal) and not such boooring languages like Java, C# and BASIC.

My next question is:

Will there be serious commersial games developed in delphi?

Share this post


Link to post
Share on other sites
Not too many commercial games are made with Delphi, unfortunately. The trouble with Delphi is that it''s not especially portable (Windows and Linux and that''s your whack). This rules out consoles, of course, which means that many games companies aren''t interested. If you''re going for PC then it''s nice. (Incidentally, the Free Pascal Compiler supports plenty more OSs than Windows and Linux, though I''ve not tried it yet.)

There have been one or two games -- Age of Wonders 1 and 2, for example. There are also some very nice looking things out there that could be of commercial quality (e.g. this, judging from the lush screenshots). Most people using Delphi are hobbyists, though, since writing games in Delphi is pretty easy and enjoyable with all the component sets. There are a few more commercial games that I should remember but can''t -- in the meantime, note that there is some nice shareware made in Delphi (which is probably where the Delphi games market has most games).

Share this post


Link to post
Share on other sites
I''ve seen some screenshots and some demos that was really good looking and made in Delphi. However, I''ve seen some cool Visual BASIC demos also, so that doesn''t tell me much.. :-/

I''m gonna try to write a 3D app in Delphi sometime..

I have a CD with Borland Delphi 6 here.. but I haven''t figured out how to set up and render a OpenGL window in Delphi..
I also tried with it''s cousin, Borland C++ Builder 5, but I cannot run that for a very long time before i crashes. It also has a lot of compiler problems since some components are written in pascal and some in C++..

Do you know of any easy way to set up such a thing in Delphi 6?

(Open GL and Direct 3D are no problems for me since I''ve used them a lot together with C++)

Share this post


Link to post
Share on other sites
If you just want a basic window then remember that NeHe has Delphi ports of his OpenGL code -- check on the left sidebar of the main page or go to one of the tutorials and find the port, if available, at the bottom of its page. Also, make sure that you take a look over at Delphi3d. The bloke who runs that site (Tom Nuydens) has a good OpenGL toolkit called DOT, which contains the most up-to-date and best gl headers you''ll find (gl.pas, glu.pas and glext.pas, I think), along with some the coolest OpenGL demos around for newer graphics cards. Delphi3d''s gl headers are much, much more comprehensive than the standard ones shipped with Delphi.

If you want to try Direct3d then you can have a look at Clootie''s conversion of the d3d headers and stuff. The advantage here is that you don''t need the SDK to develop dx apps - saving yourself a good 150megs of download time versus C++, which is nice for me (56K modem, sigh).

You''ll have to add the location of the .pas files to your library path once you''ve downloaded and extracted them. Go to the tools->environment options menu, select the library tab and press the ellipses (three dots [...]) button beside the first box, "library path". Type in the directory/directories in question and hit "add" after each one.

Once you''ve done that, just download a sample app or two and run ''em! The only other possible problem would be missing components - just install them normally (component->install component menu, hit the browse button beside the unit file name box, choose your .pas or .dcu file then okay everything away). Do this before opening the projects, if required, and only if the thing complains about not having certain components installed.

While you''re at it, think about customising the Delphi IDE (and don''t forget that you can dock stuff like the project manager and object inspector windows too!).

Share this post


Link to post
Share on other sites
Thank You! =)

And I found something cool in one of the ports from NeHe =)

procedure SwapRGB(data : Pointer; Size : Integer);
asm
mov ebx, eax
mov ecx, size

@@loop :
mov al,[ebx+0]
mov ah,[ebx+2]
mov [ebx+2],al
mov [ebx+0],ah
add ebx,3
dec ecx
jnz @@loop
end;


So easy to make asm code inside Delphi!! =)

Even better than C++ ! =)

_asm { mov blah add blah2 .. }

Share this post


Link to post
Share on other sites
Check out the Compiler & Performance page on Realworld tech. That''s a more recent benchmark, comparing the different languages/implementations.

Also, once you''ve read that, you should head on over to the Coding Challenge article, also on Realworld Tech, and you''ll see that the language/implementation isn''t as important as the choice of algorithm.

Share this post


Link to post
Share on other sites
quote:
Original post by Alimonster
Not too many commercial games are made with Delphi, unfortunately. The trouble with Delphi is that it''s not especially portable (Windows and Linux and that''s your whack). This rules out consoles, of course, which means that many games companies aren''t interested. If you''re going for PC then it''s nice. (Incidentally, the Free Pascal Compiler supports plenty more OSs than Windows and Linux, though I''ve not tried it yet.)

While this is true to a certain degree, the primary reasons that Delphi is not used for more commercial games are:
  • There are many more games developers with C/C++ experience than with Delphi experience
  • Every commercial games-oriented library is aimed at C/C++ developers
  • Development kits from the console manufacturers are targeted solely at C/C++ developers
To us, portability has only ever been an issue when it comes to compiling code for Win32, PS2, Xbox and GameCube. The commercial market for games on Linux is not financially viable. The Mac games market is not much bigger and both are probably overshadowed by the Palm and PocketPC games market.

Note that this has absolutely nothing to do with the speed you can get out of Delphi. I still love Delphi and will still continue to use it for my own hobby projects. In the commercial world it is purely a language choice based on availability for the platforms and available developer resources.

Share this post


Link to post
Share on other sites
quote:

There are many more games developers with C/C++ experience than with Delphi experience



True, but for an experienced C++ coder, delphi won''t take more than one or two days to learn completly.

quote:

Every commercial games-oriented library is aimed at C/C++ developers



If you use DX, you won''t need much libs. At least if you design the whole engine yourself.

quote:

Development kits from the console manufacturers are targeted solely at C/C++ developers



True. But that won''t stop development for the PC platform, huh?

Share this post


Link to post
Share on other sites
quote:

I''ve seen some screenshots and some demos that was really good looking and made in Delphi. However, I''ve seen some cool Visual BASIC demos also, so that doesn''t tell me much.. :-/



You seem to have hit the nail on the head, in that, you don''t need the most "hardcore" development language to knock out a nifty demo.

I could argue that people use C/C++ to make themselves seem "clever" as every gamer has heard of C, but they''ve never heard of "Delphi". Or.. I could argue that people using Delphi(such as myself) are too lazy to learn a "real language".
Both arguements are utter nonsense...

Share this post


Link to post
Share on other sites
I decided to try a little comparison between VC6 and Delphi 7 using the fastest entry from the coding challenge that NuffSaid linked to.

Visual C++ 6 code

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>

#define BASE (10000)

void ComputePi (int numdigits, int * pi) {
int alength = 40 * numdigits / 3;
int * a = (int*) malloc (alength * sizeof(int));
int piLength = 0;
int nines = 0;
int predigit = 0;
int ii, j, p;

for(ii = 0; i < alength; ++i)
a[ii] = 2;

for (j = 0; j < numdigits; ++j) {
int q = 0;

p = 2 * alength - 1;
for (ii = alength-1; ii >= 1; ii--) {
int x = BASE*a[ii] + q*(ii+1);
a[ii] = x % p;
q = x / p;
p -= 2;
}

ii = a[0];
a[0] = q % BASE;
q = (q / BASE) + ii;

if (q == (BASE-1)) {
++nines;
} else {
int k;

if (q == BASE) {
pi[piLength] = predigit + 1;
for (k = 1; k <= nines; ++k)
pi[piLength + k] = 0;
predigit = 0;
} else {
pi[piLength] = predigit;
for (k = 1; k <= nines; ++k)
pi[piLength + k] = BASE-1;
predigit = q;
}
piLength += nines + 1;
nines = 0;
}
}

free (a);

pi[piLength] = predigit;
}

int main (int argc, char * argv[]) {
int numdigits;
int * pi;
FILE* fp = fopen (argv[2], "w");
int ii, c, t;

unsigned int startTime = GetTickCount();

if (argc <= 1) {
fprintf (stderr, "usage: pi #DIGITS [FILE]");
return 1;
}

t = atoi (argv[1]);
numdigits = (t / 4) + 2;
pi = (int *) malloc ((numdigits + 1)*sizeof (int));
ComputePi (numdigits, pi);

if (argc > 2) {
fp = fopen (argv[2], "w");
} else {
/* Dunno if this is portable, but it'll work in Windoze/DOS/UNIX */
fp = fdopen (1, "w");
}

if (fp == NULL) {
fprintf (stderr, "Cannot open %s\n", argv[2]);
return 2;
}

c = 0;
fprintf (fp, "%d", pi[1]);
c++;
for (ii=2; c + 4 <= t; ii++) {
fprintf (fp, "%04d", pi[ii]);
c+=4;
}

t -= c;
if (t > 0) {
char endbuff[8];
sprintf (endbuff, "%04d", pi[ii]);
endbuff[t] = '\0';
fprintf (fp, "%s", endbuff);
}

fputc ('\n', fp);
fprintf(fp, "%dms\n", GetTickCount() - startTime);
fclose (fp);

free (pi);

return 0;
}


Delphi 7 code (straight conversion from Visual C++ 6 code)

program delphipi;

{$APPTYPE CONSOLE}

uses
SysUtils, Windows;

const
BASE = 10000;

procedure ComputePi(numdigits: Integer; pi: PIntegerArray);
var
alength: Integer;
a: PIntegerArray;
piLength, nines, predigit, ii, j, p, q, k, x: Integer;
begin
alength := 40 * numdigits div 3;
GetMem(a, alength * SizeOf(Integer));
piLength := 0;
nines := 0;
predigit := 0;
for ii := 0 to alength - 1 do
a^[ii] := 2;


for j := 0 to numdigits - 1 do
begin
q := 0;

p := 2 * alength - 1;
for ii := alength - 1 downto 1 do
begin
x := BASE * a^[ii] + q * (ii + 1);
a^[ii] := x mod p;
q := x div p;
p := p - 2;
end;

ii := a[0];
a^[0] := q mod BASE;
q := (q div BASE) + ii;

if q = BASE - 1 then
begin
nines := nines + 1;
end
else
begin
if q = BASE then
begin
pi^[piLength] := predigit + 1;
for k := 1 to nines do
pi^[piLength + k] := 0;
predigit := 0;
end
else
begin
pi^[piLength] := predigit;
for k := 1 to nines do
pi^[piLength + k] := BASE - 1;
predigit := q;
end;
piLength := piLength + nines + 1;
nines := 0;
end;
end;

FreeMem(a);

pi^[piLength] := predigit;
end;

var
numdigits: Integer;
pi: PIntegerArray;
ii, c, t: Integer;
endbuff: array[0..7] of Char;
fileP: Text;
fp: ^Text;
startTime: Cardinal;
begin
startTime := GetTickCount();

if ParamCount < 1 then
begin
WriteLn(ErrOutput, 'usage: delphipi #DIGITS [FILE]');
Exit;
end;

t := StrToInt(ParamStr(1));
numdigits := (t div 4) + 2;
GetMem(pi, (numdigits + 1) * SizeOf(Integer));
ComputePi(numdigits, pi);

if ParamCount > 1 then
begin
AssignFile(fileP, ParamStr(2));
Rewrite(fileP);
fp := @fileP;
end
else
begin
fp := @Output;
end;

c := 0;
Write(pi^[1]);
c := c + 1;
ii := 2;
while c + 4 <= t do
begin
FormatBuf(endbuff, 8, '%.4d', 4, [pi^[ii]]);
Write(fp^, endbuff);
c := c + 4;
ii := ii + 1;
end;

t := t - c;
if t > 0 then
begin
FormatBuf(endbuff, 8, '%.4d', 4, [pi^[ii]]);
endbuff[t] := #0;
Write(fp^, endbuff);
end;

WriteLn(fp^);
if fp = @fileP then
CloseFile(fp^);

FreeMem(pi);

WriteLn(Format('%dms', [GetTickCount() - startTime]));
end.


When running these with a parameter of 10000, I get the following results on a P4 2.4GHz...

pi.exe (Visual C++ 6) 2750ms
delphipi.exe (Delphi 7) 4750ms

All of this time bar 50ms or so is spent in the ComputePI() function. I'm currently stuck as to how to get the Delphi version going any faster. No optimizations jump out at me. But I will still keep trying...

[edited by - Sly on June 27, 2003 9:43:26 AM] Why is it so difficult to paste code in these forums?


[edited by - Sly on June 27, 2003 9:48:39 AM]

Share this post


Link to post
Share on other sites
My 2 cents:

I switched from Delphi to VC some time ago just for the sake of (3D) graphics programming. It seems anything related to it is based mostly on C++ (docs/libs/headers etc), so the switch definitely made my life a lot easier.

However, for normal Windows applications I''ll favor Delphi over VC any day. The way you slap things together in Delphi is still unrivaled IMO and it has a blazingly fast optimizing compiler, which is equally powerful to any compiler around. It''s elegant, stable, extensible and well documented (I learned almost everything from the help file, even the whole Win32 API is included).

Although I feel it is a little easier to get down to the core with C++, there is nothing really that can be done by the one but not by the other (the fact you can enter straight assembler code makes it capable of producing any program by default).

Share this post


Link to post
Share on other sites