我用DELPHI处理一个结构文件,大约3000条记录,用了130毫秒,同样的功能,用VB只用了30毫秒,这是什么原因,怎么提升DELPHI处理的速度
DELPHI: AssignFile(F1, strFile);
Reset(F1);
While Not EOF(F1) do
begin
Read(F1, myrecord);
arrRec[lCount].*** := myrecord.*** If EOF(F1) Then
break;
lCount := lCount + 1;
end;
CloseFile(F1);VB:
Open strFile For Random As #1 Len = Len(myrecord)
Do While Not EOF(1)
Get #1, , myrecord
If EOF(1) Then
Exit Do
End If
arrRec(lCount).*** = myrecord.***
lCount = lCount + 1
Loop
Close #1
DELPHI: AssignFile(F1, strFile);
Reset(F1);
While Not EOF(F1) do
begin
Read(F1, myrecord);
arrRec[lCount].*** := myrecord.*** If EOF(F1) Then
break;
lCount := lCount + 1;
end;
CloseFile(F1);VB:
Open strFile For Random As #1 Len = Len(myrecord)
Do While Not EOF(1)
Get #1, , myrecord
If EOF(1) Then
Exit Do
End If
arrRec(lCount).*** = myrecord.***
lCount = lCount + 1
Loop
Close #1
procedure SetTextBuf(var F: Text; var Buf [ ; Size: Integer] );DescriptionIn Delphi code, SetTextBuf changes the text file F to use the buffer specified by Buf instead of F's internal buffer. F is a text file variable, Buf is any variable, and Size is an optional expression.Each Text file variable has an internal 128-byte buffer that buffers Read and Write operations. This buffer is adequate for most operations. However, heavily I/O-bound programs benefit from a larger buffer to reduce disk head movement and file system overhead.Size specifies the size of the buffer in bytes. If Size is omitted, SizeOf(Buf) is assumed. The new buffer remains in effect until F is next passed to AssignFile.SetTextBuf can be called immediately after Reset, Rewrite, and Append, but never apply it to an open file.When SetTextBuf is called on an open file once I/O operations have taken place, data could be lost because of the change of buffer.The Delphi runtime library does not ensure that the buffer exists for the entire duration of I/O operations on the file. A common error is to install a local variable as a buffer, then use the file outside the procedure that declared the buffer.
////////////////
Eg:
program SetTextBufExample;{$APPTYPE CONSOLE}var
Source, Destination: TextFile;
AFileName: string;
AChar: Char;
Buf: array[1..32768] of Char; { 32K buffer }
begin
Write('Enter filename: ');
Readln(AFileName);
AssignFile(Source, AFileName);
{ Larger buffer for faster reads }
SetTextBuf(Source, Buf);
Reset(Source);
{ Dump text file into another file }
AssignFile(Destination, 'WOOF.DOG');
Rewrite(Destination);
while not Eof(Source) do begin
Read(Source, AChar);
Write(Destination, AChar);
end;
CloseFile(Source);
CloseFile(Destination);
end.
这一行不要试试.
其它不知道