tags:

views:

188

answers:

4

i have tested a couple of benchmarking snippets on delphi like this one:

uses
...diagnostics;

procedure TForm2.Button1Click(Sender: TObject);
var
   i,elapsed : integer;
     stopwatch : TStopwatch;
   ff: textfile;
begin
    if FileExists('c:\bench.txt') then
    DeleteFile('c:\bench.txt'); 
     stopwatch := tstopwatch.create;
     stopwatch.Reset;
     stopwatch.Start;
    AssignFile(ff,'c:\bench.txt');
    Rewrite(ff);
    for I := 1 to 999000  do
    write(ff,'Delphi programmers are ladies men :D');
    CloseFile(ff);
    stopwatch.Stop;
    elapsed := stopwatch.ElapsedMilliseconds;
    showmessage(inttostr(elapsed));

end;

doesnt matter if i run/compile under debug or release configuration the result is mostly around 900. when i switch from debug to release in visual studio(for both c++ and c#) my programs become MAGICALLY faster.i am using delphi 2010 and i activate release configuration from project manager as well as project -> configuration manager and even project -> options -> delphi compiler but with no effect why????

if it matters : i am using windows xp ,i got 1 gig ram and an intel core 2 cpu

+11  A: 
  1. Did you check, how the configurations differ? Even if they have names like RELEASE or DEBUG, they are fully configurable. You can even configure them the other way round.

  2. The code you are timing is mostly I/O related. So make sure that the IO checks are turned off in the RELEASE configuration.

  3. Delphi still creates fast code even when debugged ;)

Uwe Raabe
+1 for "check the condiguration files". +1 for "mostly I/O related". +1 for "delphi creates fast code"... @omair: if you want to see speed difference between debug and release, do it on some CPU-intensive doe. Your code is a benchmark for the HDD, you should get about the same time using ANY programming language, from perl to python, from assembler to windows batch files.
Cosmin Prund
@ uwe raabe1. how to configure configurations? i am new to world of programming and have no idea, can you point to a good tutorial on this2.i ran this i/o related code in visualstudio for c++ and c# and the results were different.3.yep i know delphi is the best ,thats why it has an army of loyal programmers :)@ cosmin prund NO the results were different for other languages under debug: delphi was the fastest ,C++ 2nd and C# slowest and under release: C++ fastest, delphi 2nd and C# still slowest
Omair Iqbal
http://docwiki.embarcadero.com/RADStudio/en/Build_Configurations_Overview
Uwe Raabe
@Uwe Raabe thanks man
Omair Iqbal
+7  A: 

In addition to what Uwe said, make sure you do a "Build" after switching the configuration. Doing a simple compile or running the app will not recompile all units with the new settings.

Like the other commenters, I also wouldn't expect too much of a difference between the two configurations given the benchmark used. The real bottleneck is the I/O and that will very likely outbalance any performance differences between DEBUG and RELEASE.

Finally, debugging in Delphi just isn't that much slower than Release builds. Heck, I sometimes run Outlook in the debugger for most of the day (I'm developing Outlook addins) without noticing any perceivable performance difference.

Oliver Giesen
its not just about this benchmark ,for any benchmark i run under delphi debug and release perform virtually identical,in my benchmarks mostly delphi is much faster than C# but slightly slower than C/C++(i am talking about release configuration here)
Omair Iqbal
+2  A: 

That's a bad test case I think. All you do is write to a file, which means most of the time is spent in Windows code, not in your Delphi code, and hence the compiler settings won't significantly affect total execution time

Giel
+2  A: 

There's nothing in your main code bulk:

for I := 1 to 999000  do
   write(ff,'Delphi programmers are ladies men :D');

that requires strenuous checks. Your choices are:

  • Range checking
  • Overflow checking
  • I/O checking

Of those three, only I/O checking will apply, and that is probably the equivalent of adding:

for I := 1 to 999000 do
begin
   hresult := Write(ff, 'Dephi programmers are ladies men :D');
   if hresult < 0 then
      raise EIOException.Create('That''s what your mom told me, in bed.');
end;

And a the CMP and JNE CPU instructions are not very complicated. They're dwarfed by writing to the hard-drive.

It runs just as fast because it is fast.

Ian Boyd