FreePascal Information Logo Friend of FreePascal Compiler Title
Articles with Feedback, FPC News Library, PDF Collection, Mail Lists, Books, Newsgroups, IRC Open online discussion areas Research and Tutorials Tools, Compilers and Utilities Blurbs about us, advertising, etc.
Welcome to the FoFPC Research Notes: "Floating Points"

Floating Points

by: G.E. Ozz Nixon Jr.
Published: August 2009
©opyright 2009 by Friends of FPC



      As stated in the optimization page about "div"ision, I mentioned how Real worked faster than Extended. So, I took the original test program and expanded it to cover the Floating Point types from the Free Pascal web site. Here is my test code:
    Download Source IconDownload floats.pas source
Uses
   dxutil_environment;// contains TimeCounter for Windows, Linux and Mac

Var
   Loop:LongWord;
   StartTime:Comp;
   X:Longint;
   Si:SmallInt;
   I:Int64;
   Y:Real;
   //F:Float;
   E:Extended;
   S:Single;
   D:Double;
   C:Comp;
   W:Word;
   Lw:LongWord;
   Qw:QWord;

Begin
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do Si:=SizeOf(LongWord) div 2;
   System.Writeln('SmallInt: ',Trunc(Trunc(TimeCounter)-StartTime));
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do X:=SizeOf(LongWord) div 2;
   System.Writeln('LongInt: ',Trunc(Trunc(TimeCounter)-StartTime));
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do I:=SizeOf(LongWord) div 2;
   System.Writeln('Int64: ',Trunc(Trunc(TimeCounter)-StartTime));
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do W:=SizeOf(LongWord) div 2;
   System.Writeln('Word: ',Trunc(Trunc(TimeCounter)-StartTime));
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do Lw:=SizeOf(LongWord) div 2;
   System.Writeln('LongWord: ',Trunc(Trunc(TimeCounter)-StartTime));
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do Qw:=SizeOf(LongWord) div 2;
   System.Writeln('QuadWord: ',Trunc(Trunc(TimeCounter)-StartTime));
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do Y:=SizeOf(LongWord) / 2;
   System.Writeln('Real: ',Trunc(Trunc(TimeCounter)-StartTime));
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do Y:=SizeOf(LongWord) / 2;
   System.Writeln('Extended: ',Trunc(Trunc(TimeCounter)-StartTime));
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do S:=SizeOf(LongWord) / 2;
   System.Writeln('Single: ',Trunc(Trunc(TimeCounter)-StartTime));
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do D:=SizeOf(LongWord) / 2;
   System.Writeln('Double: ',Trunc(Trunc(TimeCounter)-StartTime));
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do C:=SizeOf(LongWord) / 2;
   System.Writeln('Comp: ',Trunc(Trunc(TimeCounter)-StartTime));
end.

Linux:
SmallInt: 332
LongInt: 332
Int64: 289
Word: 302
LongWord: 166
QuadWord: 332
Real: 275
Extended: 209
Single: 312
Double: 307
Comp: 303

Mac:
SmallInt: 206
LongInt: 194
Int64: 271
Word: 195
LongWord: 193
QuadWord: 262
Real: 396
Extended: 404
Single: 271
Double: 395
Comp: 391

    On 32bit Unixes, it shows that LongWord (32bit Unsigned Long Int) is the fastest of the whole number types, while the other types have different results depending upon the operating system.

G.E. Ozz Nixon Jr.
 Links and Products we find useful



ButtonGenerator.com
Valid XHTML 1.0 Transitional Internet Map
Programmer's Heaven
grat-i-fi-ca-tion - noun
the state of being gratified; great satisfaction.


"FoFPC is simply brilliant, a single site with exactly what I was looking for - you made this so easy for me!"

Doug Edwards
eXtreme Accounting
Locations of visitors to this page world map hits counter
Copyright 2009 by 3F, LLC. All rights reserved. Worldwide.
Your request was processed by server #3 in 0.002469 secs.

sponsor
This sponsor helps us with our documentation