Performance testing
Machine Configuration: Dell E6420 4 GB Ram 32- Bit i-7 Core (cores dont matter in this case.Parallel test for later)
Input File: 350+ MB tab delimited txt file
StreamReader
using System;
using System.Diagnostics;
using System.IO;
namespace FileReaderPerf
{
class Program
{
static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
try
{
using (StreamReader oReader = new StreamReader(@"c:\File.txt"))
{
string sLine = oReader.ReadLine();
while (sLine != null)
{
Console.WriteLine(sLine);
sLine = oReader.ReadLine();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds);
Console.WriteLine("RunTime " + elapsedTime);
Console.Read();
}
}
}
StreamReader using a larger buffer size
using (StreamReader oReader = new StreamReader(@"c:\File.txt",Encoding.ASCII,false,8092))
Machine Configuration: Dell E6420 4 GB Ram 32- Bit i-7 Core (cores dont matter in this case.Parallel test for later)
Input File: 350+ MB tab delimited txt file
StreamReader
using System;
using System.Diagnostics;
using System.IO;
namespace FileReaderPerf
{
class Program
{
static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
try
{
using (StreamReader oReader = new StreamReader(@"c:\File.txt"))
{
string sLine = oReader.ReadLine();
while (sLine != null)
{
Console.WriteLine(sLine);
sLine = oReader.ReadLine();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds);
Console.WriteLine("RunTime " + elapsedTime);
Console.Read();
}
}
}
StreamReader using a larger buffer size
using (StreamReader oReader = new StreamReader(@"c:\File.txt",Encoding.ASCII,false,8092))
File.ReadLines
using System;
using System.Diagnostics;
using System.IO;
namespace FileReaderPerf
{
class Program
{
static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
try
{
foreach(string sLine in File.ReadLines(@"c:\File.txt"))
Console.WriteLine(sLine);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds);
Console.WriteLine("RunTime " + elapsedTime);
Console.Read();
}
}
}