in this example fpc 2.6.4 is faster than 3.1.1 (fpc 2.6.4 show 1482ms , fpc 3.1.1 show 1684ms)
both example compiled with -O3 , in win7 32bits.
program mandelbrot;
uses windows;
const
ixmax = 2500;
iymax = 2000;
cxmin = -2.5;
cxmax = 1.5;
cymin = -2.0;
cymax = 2.0;
maxcolorcomponentvalue = 255;
maxiteration = 200;
escaperadius = 2;
type
colortype = record
red : byte;
green : byte;
blue : byte;
end;
var
ix, iy : integer;
cx, cy : real;
pixelwidth : real = (cxmax - cxmin) / ixmax;
pixelheight : real = (cymax - cymin) / iymax;
filename : string = 'new1.ppm';
comment : string = '# ';
outfile : textfile;
color : colortype;
zx, zy : real;
zx2, zy2 : real;
iteration : integer;
er2 : real = (escaperadius * escaperadius);
tm : longword;
begin
tm := GetTickCount();
{$I-}
assign(outfile, filename);
rewrite(outfile);
if ioresult <> 0 then
begin
writeln(stderr, 'unable to open output file: ', filename);
exit;
end;
writeln(outfile, 'P6');
writeln(outfile, ' ', comment);
writeln(outfile, ' ', ixmax);
writeln(outfile, ' ', iymax);
writeln(outfile, ' ', maxcolorcomponentvalue);
for iy := 1 to iymax do
begin
cy := cymin + (iy - 1)*pixelheight;
if abs(cy) < pixelheight / 2 then cy := 0.0;
for ix := 1 to ixmax do
begin
cx := cxmin + (ix - 1)*pixelwidth;
zx := 0.0;
zy := 0.0;
zx2 := zx*zx;
zy2 := zy*zy;
iteration := 0;
while (iteration < maxiteration) and (zx2 + zy2 < er2) do
begin
zy := 2*zx*zy + cy;
zx := zx2 - zy2 + cx;
zx2 := zx*zx;
zy2 := zy*zy;
iteration := iteration + 1;
end;
if iteration = maxiteration then
begin
color.red := 0;
color.green := 0;
color.blue := 0;
end
else
begin
color.red := 255;
color.green := 255;
color.blue := 255;
end;
write(outfile, chr(color.red), chr(color.green), chr(color.blue));
end;
end;
close(outfile);
writeln(GetTickCount() - tm,'ms');
readln;
end.