//源程序如下,含测试程序
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IniFiles;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);//进行重复数据删除
procedure Button2Click(Sender: TObject);//生成测试数据
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
H1: TStringList;
STime: Integer;//计时
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Times: Integer;//数据量
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var I, J: Integer;
NewS: string;
begin
H1.LoadFromFile('d:/2.txt');
Memo1.Lines.Add(IntToStr(H1.Count - 1));
STime := GetTickCount;
I := 1;
J := H1.Count - 1;
H1.Sort ;
NewS := H1.Strings[0];
while I <= Jdo
begin
if H1.Strings = NewS then
begin
H1.Delete(I);
Dec(J);
end
else
begin
NewS := H1.Strings;
Inc(I);
end;
end;
Memo1.Lines.Add(IntToStr(GetTickCount - STime));
H1.SaveToFile('D:/3.Txt');
end;
procedure TForm1.Button2Click(Sender: TObject);
var I: Integer;
begin
Times := StrToInt(Edit1.Text);//根据输入确定数据量
H1.Clear;
STime := GetTickCount;
for I := 0 to Timesdo
H1.Add(IntToStr(Random(Round(Times ))));
H1.SaveToFile('D:/2.Txt');
Memo1.Lines.Add(IntToStr(GetTickCount - STime));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
H1 := TStringList.Create;
Randomize;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
H1.Free;
end;
end.