Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- {$R *.res}
- {$define UseGenericList}
- uses
- WinApi.Windows, System.SysUtils, System.Classes, System.Generics.Collections;
- const
- ListItemCount = 100 * 1000;
- {$if defined(UseGenericList)}
- const TestName = 'List<Integer>';
- procedure Test;
- var
- Start: Cardinal;
- List: TList<Integer>;
- I: Integer;
- begin
- List := TList<Integer>.Create;
- try
- List.Capacity := ListItemCount;
- for I := 0 to ListItemCount div 2 - 1 do
- List.Add(I);
- for I := ListItemCount div 2 to ListItemCount - 1 do
- List.Add(ListItemCount - I);
- Start := GetTickCount;
- List.Sort;
- WriteLn(GetTickCount - Start);
- finally
- List.Free;
- end;
- end;
- {$else}
- const TestName = 'Classes.List';
- procedure Test;
- var
- Start: Cardinal;
- List: TList;
- I: Integer;
- begin
- List := TList.Create;
- try
- List.Capacity := ListItemCount;
- for I := 0 to ListItemCount div 2 - 1 do
- List.Add(Pointer(I));
- for I := ListItemCount div 2 to ListItemCount - 1 do
- List.Add(Pointer(ListItemCount - I));
- Start := GetTickCount;
- List.SortList(function (Item1, Item2: Pointer): Integer
- begin
- Result := Integer(Item1) - Integer(Item2)
- end);
- WriteLn(GetTickCount - Start);
- finally
- List.Free;
- end;
- end;
- {$endif}
- begin
- try
- Test;
- except
- on E: Exception do
- Writeln(TestName, ':', E.ClassName, ': ', E.Message);
- end;
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement