When using ReadAllText method to read a log file with a size of 21.83MB, it takes between 7 seconds (for powerful CPU) to 12 seconds (for weak CPU).
SOLUTION | SOLVED? |
---|---|
|
Failed |
StreamReader.ReadLine
Source:
Dim file As New FileInfo("path\to\file") Using reader As StreamReader = file.OpenText() While Not reader.EndOfStream Dim nextLine As String = reader.ReadLine() ProcessLine(nextLine) End While End Using
|
NO
This method generates error maybe because the memory usage increase overtime due to many lines data read Or maybe because i don’t actually know the correct way to use this method |
StreamReader.ReadBlock Source: Const MAX_BYTES As Integer = 1048576 * 5 '=10 MB Dim bytesRead(MAX_BYTES) As Char Dim numBytesRead As Integer Dim currentPos As Integer = 0 Dim strFileName As String Dim strm As System.IO.Stream Dim TextLine As String Dim FileDetail As IO.FileInfo OpenFileDialogMain.ShowDialog() strm = OpenFileDialogMain.OpenFile() strFileName = OpenFileDialogMain.FileName.ToString() Using reader As System.IO.TextReader = _ System.IO.File.OpenText(strFileName) numBytesRead = _ reader.ReadBlock(bytesRead, currentPos, MAX_BYTES) TextLine = reader.ReadLine() End Using txtEditor.Text = New String(bytesRead) txtEditor.Text += TextLine txtEditor.Text = txtEditor.Text & vbCrLf & Now
|
NO
This method can be used to fetch .log file but a bit slower than ReadAllText() method. Completion time to load the log file into textbox is approximately 11-12 seconds |
File.ReadAllLines
Source: |
NO
This method opens a text file, reads all lines of the file into a string array, and then closes the file. To load the string array into the textbox will use the same method as ReadLine() which is using Looping |
Test Methodology
TEST | DELL-E6410 | MSI |
---|---|---|
StreamReader.Readline
How long does it take for Control Panel to load the log file |
No result because of error | No result because of error |
StreamReader.ReadBlock
How long does it take for Control Panel to load the log file “X:\Support\Support Cases\264 (I19-2460-MACRO-ASP)\2020_1_14.log”, File size: 21.83MB |
11-12 seconds | 11-12 seconds |
File.ReadAllLines
How long does it take for Control Panel to load the log file “X:\Support\Support Cases\264 (I19-2460-MACRO-ASP)\2020_1_14.log”, File size: 21.83MB |
No result because of error | No result because of error |
What is the CPU? | Intel(R) Core(TM) i5 CPU M560 @ 2.67GHz | Intel(R) Core(TM) i5-4200 CPU @ 2.50GHz |
What is the RAM? | 4.00 GB (3.43 usable) | 8.00 GB |
Conclusion: stick with ReadAllText method to read a log file.