- program Project2;
- {$APPTYPE CONSOLE}
- uses
- SysUtils,
- Classes,
- System,
- Windows, //only for gettickcount
- IniFiles,
- Hash;
- type
- TTest = class
- str: String;
- constructor Create;
- procedure test;
- end;
- PTest = ^TTest;
- var
- hash: TStringHash;
- s: TStringList;
- sh: THashedStringList;
- x,i,i2: Integer;
- test: array of TTest;
- test2: PTest;
- time: Integer;
- constructor TTest.Create;
- begin
- Randomize;
- str := FloatToStr(random);
- end;
- procedure TTest.test;
- begin
- WriteLn(str);
- end;
- function RandomString(strlength: integer): string;
- var
- temp : integer;
- begin
- randomize;
- repeat
- temp := random(122); //ggf. erhöhen
- if temp in [48..57{0-1}, 65..90{A-Z}, 97..122{a-z}] then
- //Kann um beliebige ASCII-Zeichen erweitert werden,
- //ggf. den Wert in Random hochsetzen
- result := result + Chr(temp);
- until length(result) = strlength;
- end;
- begin
- hash := TStringHash.Create(1000000);
- time := GetTickCount;
- SetLength(test, 1000001);
- for x := 0 to 1000000 do
- begin
- test[x] := TTest.Create;
- hash.Add(IntToStr(x), @test[x]);
- end;
- WriteLn(IntToStr(GetTickCount - time));
- time := GetTickCount;
- for x := 0 to 10000 do
- begin
- test2 := hash.Get(IntToStr(Random(999999)+1));
- //test2^.test;
- end;
- WriteLn(IntToStr(GetTickCount - time));
- hash.Free;
- s := TStringList.Create;
- SetLength(test, 1000001);
- time := GetTickCount;
- for x := 0 to 1000000 do
- begin
- test[x] := TTest.Create;
- s.Add(IntToStr(x));
- end;
- WriteLn(IntToStr(GetTickCount - time));
- time := GetTickCount;
- for x := 0 to 10000 do
- begin
- s.Find(IntToStr(Random(999999)+1), i);
- //test[i].test;
- end;
- WriteLn(IntToStr(GetTickCount - time));
- s.Free;
- SetLength(test, 0);
- sh := THashedStringList.Create;
- SetLength(test, 1000001);
- time := GetTickCount;
- for x := 0 to 1000000 do
- begin
- test[x] := TTest.Create;
- sh.Add(IntToStr(x));
- end;
- WriteLn(IntToStr(GetTickCount - time));
- time := GetTickCount;
- for x := 0 to 10000 do
- begin
- sh.Find(IntToStr(Random(999999)+1), i);
- //test[i].test;
- end;
- WriteLn(IntToStr(GetTickCount - time));
- sh.Free;
- SetLength(test, 0);
- ReadLn;
- end.