Friday 28 November 2008

The smallest Hello, World in Delphi

This is the source code:
program p;
Writeln ('Hello, World');

Program info (Delphi 2009):

* Code size 14284 bytes
* Data size 12988 bytes
* Initial stack size 16384 bytes
* File size 21504 bytes


* Using a standard .cmd batch file, this application can be started 10000 times in 77 seconds on a standard Core 2 laptop using Windows XP. That means 7,7 milliseconds per run.

A minimal GUI app:

program p;
MessageBox (0,'Message','Hello, World',MB_OK);

Program info (Delphi 2009):

* Code size 11744 bytes
* Data size 12984 bytes
* Initial stack size 16384 bytes
* File size 18432 bytes

Both run on:

* Windows 95 and later
* Windows NT 3 and later
* Linux using Wine

In order to understand the relation to other languages, you can have a look at this article about Java (translations tools here).


Fabio Gomes said...

Why the console version is bigger than the GUI version?

Anonymous said...

isn't 1 empty form take around 70kb on Delphi (due to vcl use)?
oh i see you must be code that directly on .dpr :D

Lars D said...
This comment has been removed by the author.
Lars D said...

A minimal Delphi 2009 app with 1 GUI form is:

Code size: 398652 bytes
Data size: 28612 bytes
Initial stack size: 16384 bytes
File size: 505856 bytes

Executables are bigger with Delphi 2009 than with previous versions, probably because everything now uses UTF-16.

A Delphi executable can be run on all the same platforms that I mentioned in the blog post, and it requires no external DLLs or runtime. It can be installed on a computer where you have only guest permissions.

Unknown said...

Fabio, the Console version is bigger because Writeln code is implemented by the compiler, instead of MesageBox's that is only a wrapper function to the one provided by Windows API.

Anonymous said...

I wondered where this post was going to, until I read the article about Java. That really put a smile on my face :-)

You cheated a bit by calling a program that launches a Windows dialog a GUI app.

For folks who are looking for a way to create really compact Windows GUI apps with Delphi, take look at KOL.