Advertisement
Guest User

String test

a guest
Mar 21st, 2023
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.20 KB | Software | 0 0
  1. program stings;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. {$R *.res}
  6.  
  7. uses
  8.   Windows,
  9.   System.SysUtils;
  10.  
  11. const
  12.   Buffer: string = 'halalconta';
  13. var
  14.   Test: string;
  15. begin
  16.   try
  17.  
  18.     var Start := GetTickCount;
  19.     for var Round := 1 to 100000 do
  20.     begin
  21.       Test := '';
  22.       for var Index := 1 to 1000 do
  23.         Test := Test + Buffer;
  24.     end;
  25.     var TimeSpanS := GetTickCount - Start;
  26.  
  27.     WriteLn(Test.Substring(0, 32));
  28.     var Builder := TStringBuilder.Create;
  29.  
  30.     Start := GetTickCount;
  31.     for var Round := 1 to 100000 do
  32.     begin
  33.       Builder.Length := 0;
  34.       for var Index := 1 to 1000 do
  35.         Builder.Append(Buffer);
  36.     end;
  37.     var TimeSpanB := GetTickCount - Start;
  38.  
  39.     WriteLn(Builder.ToString(0, 32));
  40.  
  41.     SetLength(Test, 10000);
  42.     Start := GetTickCount;
  43.     for var Round := 1 to 100000 do
  44.       for var Index := 0 to 999 do
  45.         Move(PByte(Buffer)^, Test[Index * 10 + 1], 20);
  46.     var TimeSpanM := GetTickCount - Start;
  47.  
  48.     WriteLn(Test.Substring(0, 32));
  49.     WriteLn(Format('Concat: %d ms, Builder: %d ms, Move: %d ms', [TimeSpanS, TimeSpanB, TimeSpanM]));
  50.  
  51.   except
  52.     on E: Exception do
  53.       Writeln(E.ClassName, ': ', E.Message);
  54.   end;
  55.   ReadLn;
  56. end.
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement