procedure WriteToFile(const FileName: string);
var
F: THandle;
P, Buffer: PChar;
S: string;
I, Len, BufLen, BufSize: Integer;
begin
F := FileCreate(FileName, fmCreate);
try
BufSize := 500 * 1024;
Buffer := AllocMem(BufSize);
try
P := Buffer;
BufLen := 0;
S := 'abcdefghijklmn' + sLineBreak;
Len := Length(S);
for I := 0 to 1107568 do
if Len > 0 then
begin
if (BufLen + Len) > BufSize then
begin
FileWrite(F, Buffer^, BufLen);
BufLen := 0;
P := Buffer;
end;
Move(S[1], P^, Len);
Inc(P, Len);
Inc(BufLen, Len);
end;
if BufLen > 0 then
FileWrite(F, Buffer^, BufLen);
finally
FreeMem(Buffer);
end;
finally
CloseHandle(F);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
S: Cardinal;
begin
S := GetTickCount;
WriteToFile('C:/test.txt');
Caption := Format('%f', [(GetTickCount - S) / 1000])
end;