Can I accelerate the speed of this code? lazarus / 9-Editor ---------------------------------------------------------------------- Danail · 2007-03-14 20:11 I use a TStrings component for holding strings during executing of the program. I saw that it is quite more time consuming compared with if I save the strings in a text file. I don't know why is this hapening, but think that there is no logick this to hapen, so maybe I am not doing something like it must be done. Here is sample of what i do:  var   TheListOfOptions: TStrings;   a_new_option: String;  begin   TheListOfOptions := TStringList.Create;   {doing long but fast for executing a_new_option formating. }   TheListOfOptions.Add(a_new_option);  end;  This code become considerably slower than that one:  var   F1: TextFile;   a_new_option: String;  begin   AssignFile(F1, 'Options.TXT');   Append(F1);   {doing the very same a_new_option formating. }   WriteLn(F1, a_new_option);   CloseFile(F1);  end;  I don't think that working only with the RAM of the PC - I suppose that TStrings works only with the RAM - must be slower than working with the HardDrive, because the hard drive is slower than the RAM, so maybe I am not using the TStrings correctly. Any ideas why is it working slower are wellcome . ---------------------------------------------------------------------- Phil · 2007-03-14 21:14 Quote from: "Danail"I use a TStrings component for holding strings during executing of the program. I saw that it is quite more time consuming compared with if I save the strings in a text file. How do you know it's slower. One string doesn't make a very good test. Working with strings in memory will be faster than writing them to a text file and re-reading them later. And also much simpler code. Use a TStringList since it has additional properties and methods over a TStrings (sorting, etc.). I've used TStringList for years on Delphi with extremely large number of strings and it is very fast. FPC's TStringList is also very fast. ---------------------------------------------------------------------- Vincent Snijders · 2007-03-14 21:55 Before adding the strings set the capacity of the list. ---------------------------------------------------------------------- theo · 2007-03-14 21:56 Your code doesn't show enough. Do you free the Stringlist when you're done? Which amount of data are you talking about? Is your StringList sorted? How do you measure the time? ---------------------------------------------------------------------- Danail · 2007-03-17 17:35 > Do you free the Stringlist when you're done? Yes. > Which amount of data are you talking about? At arround of 100 inputs of strings. > Is your StringList sorted? No. > How do you measure the time? Well I make a show message like ShowMessage('OK'); after the job is done and ... then my PC is slow and when running on Windows Me it is easy to see the time diference, because when files are used there is no delay, and when TStrings are used there is 2 seconds !!!! delay. ---------------------------------------------------------------------- Vincent Snijders · 2007-03-17 19:07 I would like to see the complete running code of that. Can you upload it somewhere?