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: "For Loop"

For Loop

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



      Well testing other routines in my dxutil suite, I decided to evalute common implementation of for loops.

    Download Source IconDownload for1.pas source
Uses
   dxutil_environment;// contains TimeCounter for Windows, Linux and Mac

Var
   Loop:LongWord;
   StartTime:Comp;
   S,Result:AnsiString;
   Loop2:Longint;

Begin
   S:='AbCdEfGhIjKlMnOpQrStUvWxYz';
   Writeln('Uppercase()');
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do begin
      Result:=S;
      for Loop2 := 1 to Length(Result) do
         if Result[Loop2] in ['a'..'z'] then Dec(Result[Loop2], 32);
   end;
   System.Write('Up ',Trunc(Trunc(TimeCounter)-StartTime));
   StartTime:=Trunc(TimeCounter);
   For Loop:=1 to 100000000 do begin
      Result:=S;
      for Loop2 := Length(Result) downto 1 do
         if Result[Loop2] in ['a'..'z'] then Dec(Result[Loop2], 32);
   end;
   System.Writeln(' DownTo ',Trunc(Trunc(TimeCounter)-StartTime));
end.

     The results, Up 25021 DownTo 24069... the downto is 1000ms faster (over 100 million calls). Mostly likely due to the Length of Result is not being evaluated for Loop2 like it is for the way people normally write these types of loops.

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.


"If you have a testimonial you would like to share, feel free to email me directly at ozznixon (at) (gmail.com)"

Your Web Master
Friends-Of-FPC.org
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.001604 secs.

sponsor
Click to visit our paid sponsor