Tutorial :Switching from debug to release configuration having no effect on performance?


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;  

It does not matter if I run/compile under debug or release configuration the result is 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 1gb RAM and an Intel Core2 CPU.


  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 ;)


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.


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


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »