Board index » delphi » Re: Working with very large text files - VB(Visual Basic) is faster than Delphi?
Doug Olson
Delphi Developer |
Re: Working with very large text files - VB(Visual Basic) is faster than Delphi?2006-08-04 05:46:09 AM delphi170 I constructed two sample applications (VB6 and Delphi 2006 Win32) that do a simple search through a text file line by line. (see source code at that bottom of this email). I must be off on my approach or is there a 3rd party solution to make this faster... this file has 2.4 million lines (rows) and is 806MB in size. VB6 ---------------------- 8/3/2006 4:35:54 PM Lines: 2401548 Found: 37 8/3/2006 4:37:25 PM 90.28125 DELPHI 2006 Win32 ---------------------- 8/3/2006 4:32:04 PM Lines: 2401548 Found: 37 8/3/2006 4:34:41 PM 156.69099970255 SOURCE ========== VB --------------- Private Sub cmdSimpleSearch_Click() Dim sBuffer As String Dim nCount As Long Dim nLine As Long Dim sSearch As String Dim sFileIn As String Dim fIn As Long Dim dStart As Single Dim dEnd As Single sFileIn = File1.Path + "\" + File1.filename txtText1.Text = Now & vbCrLf dStart = Timer fIn = FreeFile Open sFileIn For Input As #fIn sSearch = Me.txtSearch.Text Do While Not EOF(fIn) Line Input #fIn, sBuffer If InStr(sBuffer, sSearch)>0 Then nCount = nCount + 1 End If nLine = nLine + 1 Loop Close #fIn dEnd = Timer txtText1.Text = txtText1.Text + "Lines: " & nLine & vbCrLf txtText1.Text = txtText1.Text + "Found: " & nCount & vbCrLf txtText1.Text = txtText1.Text & Now & vbCrLf txtText1.Text = txtText1.Text & dEnd - dStart lblStatus.Caption = "Searched " + Str(nLine) + " lines, found: " + Str(nCount) + " of " + sSearch End Sub ------------------ DELPHI ------------------ procedure TForm1.cmdSimpleSearchClick(Sender: TObject); var hHandle : TextFile; sBuffer : String; sSearch : String; nCount : Integer; nFound : Integer; dStart : TDateTime; dEnd : TDateTime; begin Memo1.Lines.Clear ; nCount := 0 ; nFound := 0 ; if Dialog.Execute then begin sSearch := Edit1.Text ; Memo1.Lines.Add((DateTimeToStr(Now))); dStart := Now; AssignFile(hHandle, Dialog.FileName); Reset(hHandle); while Not EOF(hHandle) do begin Readln(hHandle, sBuffer); if Pos(sSearch, sBuffer)>0 then Inc(nFound); Inc(nCount); end; CloseFile(hHandle); dEnd := Now; Memo1.Lines.Add('Lines: ' + IntToStr(nCount)); Memo1.Lines.Add('Found: ' + IntToStr(nFound)); Memo1.Lines.Add((DateTimeToStr(Now))); Memo1.Lines.Add(FloatToStr(SecondSpan(dEnd, dStart))); end; end; |