Advertisement
Guest User

Untitled

a guest
Jan 14th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.20 KB | None | 0 0
  1. (*
  2.  
  3.   Result for my environment:
  4.  
  5.   THashedStringList: 00:00:01.093
  6.   TMyList: 00:00:00.093
  7.   TMyList: 00:00:00.078
  8.   THashedStringList: 00:00:01.093
  9.  
  10. *)
  11.  
  12. program project1;
  13.  
  14. {$APPTYPE CONSOLE}
  15.  
  16. uses
  17.   System.Generics.Collections, System.Contnrs, Classes, SysUtils,
  18.   System.IniFiles;
  19.  
  20. type
  21.   TMyList = class(TDictionary<string, string>)
  22.   end;
  23.  
  24. const
  25.   COUNT = 100000; // 100.000
  26.   FMT = 'hh:nn:ss.zzz';
  27. var
  28.   I: Integer;
  29.   B, E: TDateTime;
  30.   Name: string = '';
  31.   Value: string = '';
  32.   SL: TStrings;
  33.   LS: TMyList;
  34. begin
  35.   SL := THashedStringList.Create;
  36.   LS := TMyList.Create;
  37.   try
  38.     B := Now;
  39.     // add name and value
  40.     for I := 1 to COUNT do
  41.     begin
  42.       Name := IntToStr(I);
  43.       SL.Add(Name + '=' + Name);
  44.     end;
  45.     // get value from name
  46.     for I := 1 to COUNT do
  47.     begin
  48.       Name := IntToStr(I);
  49.       Value := SL.Values[Name];
  50.     end;
  51.     E := Now;
  52.     SL.Clear;
  53.     WriteLn(SL.ClassName, ': ', FormatDateTime(FMT, E - B));
  54.  
  55.     B := Now;
  56.     // add name and value
  57.     for I := 1 to COUNT do
  58.     begin
  59.       Name := IntToStr(I);
  60.       LS.Add(Name, IntToStr(I));
  61.     end;
  62.     // get value from name
  63.     for I := 1 to COUNT do
  64.     begin
  65.       Name := IntToStr(I);
  66.       Value := LS[Name];
  67.     end;
  68.     E := Now;
  69.     LS.Clear;
  70.     WriteLn(LS.ClassName, ': ', FormatDateTime(FMT, E - B));
  71.  
  72.     B := Now;
  73.     // add name and value
  74.     for I := 1 to COUNT do
  75.     begin
  76.       Name := IntToStr(I);
  77.       LS.Add(Name, IntToStr(I));
  78.     end;
  79.     // get value from name
  80.     for I := 1 to COUNT do
  81.     begin
  82.       Name := IntToStr(I);
  83.       Value := LS[Name];
  84.     end;
  85.     E := Now;
  86.     LS.Clear;
  87.     WriteLn(LS.ClassName, ': ', FormatDateTime(FMT, E - B));
  88.  
  89.     B := Now;
  90.     // add name and value
  91.     for I := 1 to COUNT do
  92.     begin
  93.       Name := IntToStr(I);
  94.       SL.Add(Name + '=' + Name);
  95.     end;
  96.     // get value from name
  97.     for I := 1 to COUNT do
  98.     begin
  99.       Name := IntToStr(I);
  100.       Value := SL.Values[Name];
  101.     end;
  102.     E := Now;
  103.     SL.Clear;
  104.     WriteLn(SL.ClassName, ': ', FormatDateTime(FMT, E - B));
  105.  
  106.     WriteLn('Press [ENTER] to exit ...');
  107.     ReadLn;
  108.   finally
  109.     SL.Free;
  110.     LS.Free;
  111.   end;
  112. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement