[fpc-pascal]Performance: Free Pascal vs GNU Pascal
Marco van de Voort
Marcov at stack.nl
Sun Dec 29 14:31:10 CET 2002
> How fast is the code generated by FPC versus GPC? Have there been any
> benchmarks comparing FPC with GPC....especially on Windows...in other
> words how well are these compilers optimizing?
The main problem is what you want to optimize. Ordinary application
code, or tightly looped algoritms, e.g. numerical code?
GPC might be a bit better on purely numerical stuff. But this will only
appear in benchmarks, and maybe for some kinds of scientific
calculations. (iow, if you plan to do nothing than matrix operations,
and speed is already a major issue, GPC is an option)
Ordinary code performance also strongly depends on the speed of
the runtime, specially if you start using strings, exceptions etc.
> I haven't written Pascal code in years...but the Borland compilers made
> code that "screamed"....on those old platforms. While I realize a
> comparison might not be possible, how does FPC (and GPC) compare to the
> old Borland style compilers?
Both are faster, since BP is not very optimizing. Keep in mind
though (specially with the go32v2 dos platform for both compiler)
that binary startup times for dos+ 32-bits extender or windows are
slower than 16-bits dos. This may be perceived as "slower" but it is
an OS problem.
(it is e.g. gone under Unix, while still all the code is generated by roughly the
same compiler)
> Also, does anyone have a feeling of how the current Pascal optimizations
> compare to the C compiler optimizations for various platforms? In other
> words, is there any merit to the claim I'ver heard that the fastest
> compiled code comes from C compilers?
There are two approaches to this question:
1. The compiler writers approach:
This is not true. There has been extensive discussion about this in
comp.lang.pascal.ansi-iso, with some people developping compilers
for a living (e.g. from Compaq).
Both languages are as fast when a certain minimal amount of
optimization is implemented in the compiler. Before that, C is
generally faster, simply because the average C programmer writes
more low level code.
After that, the quality is pretty much linear with the time spent on the
optimizer, regardless of being C or Pascal. (Pascal is actually
easier to develop an optimizer for, because it has less rules of
course)
2. The programmers approach.
The average Pascal code _is_ slower. But that is a problem (or
more likely, a deliberate design decision) of the writer of the
average code, not the language.
E.g. while in C people spell out e.g. string operations in terms of
pointers and chars (like you could in FPC/BP with pchar's and
strings unit), but the average programmer will use BP shortstrings or
Delphi ansistrings (FPC Delphi modes), which have a penalty of a
between 0 and 10,20 percents for some operations. (on equivalent
string code, not applicationwide). But Pascal strings work a lot
easier, and are less bug-prone.
If you want examples of this, (performance/ease of programming
tradeoffs) look e.g. in the FPC RTL. That is a large library where a
lot of work was done by good programmers, and it shows. This is
generally not harder than writing equivalent C code.
IMHO that is the strong side of the Borlandlike Pascal compilers.
One can achieve C speeds when necessary (if the compiler is good
enough), while using nicer language options for less speed
dependant parts.
> My questions are loosely structured, and perhaps naive...but nonetheless
> important as I make a fundamental decision regarding my development
> environment. Any light on the subject would be appreciated.
Free Pascal is good enough for nearly everything, performancewise.
If speed is a _real_ problem, the maximally ten percent overall speed
of recompiling your app with GPC or rewriting it in GCC, won't save
you, and you can't probably hack it with free compilers anyway, and
you'll enter the realm of specialised commercial compilers. (and for
scientific applications, that will be neither Pascal or C, but Fortran
most likely)
IOW choose the one that matches your criteria the best
(based on things like IDE, debugging, language features, source
code availability, development speed etc)
I know the ten percent speed difference sounds conservative, but,
contrary to benchmarks, it is my experience for larger applications.
(which also hold a large percentage of relatively unoptimizable
code).
--
For the GPC/FPC tradeoff, some people like GPC, some (more :-))
like FPC , so the advise is the same here as I give in newsgroups:
Play with both, and/or try to find some source code that is like the
application you want to make, and see how easy you can get it to
run with either. See if it matters performancewise (I doubt it)
For the rest: If you want to start using Delphi features in the future,
choose FPC. (and I promise, you will, they are nice :-)
More information about the fpc-pascal
mailing list