Skip to content

Instantly share code, notes, and snippets.

@Ruszrok

Ruszrok/ReaderComparer.cs

Last active Dec 30, 2015
Embed
What would you like to do?
Microsoft.VisualBasic.FileIO.TextFieldParser vs String.Split
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic.FileIO;
using System.Diagnostics;
namespace ReaderComparer
{
class Program
{
static string[] ReadArrayFromFile(string fileName)
{
string[] result = null;
using (var reader = new StreamReader(fileName))
{
var size = Convert.ToInt32(reader.ReadLine());
result = reader.ReadLine()
.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
}
return result;
}
static string[] ReadArrayFromFileVb(string fileName)
{
var parser = new TextFieldParser(fileName);
parser.HasFieldsEnclosedInQuotes = true;
parser.SetDelimiters(" ");
string[] fields = null;
while (!parser.EndOfData)
{
fields = parser.ReadFields();
}
parser.Close();
return fields;
}
static void Main(string[] args)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
ReadArrayFromFile(args[0]);
stopwatch.Stop();
Console.WriteLine(stopwatch.ElapsedMilliseconds);
var stopwatch1 = new Stopwatch();
stopwatch1.Start();
ReadArrayFromFileVb(args[0]);
stopwatch1.Stop();
Console.WriteLine(stopwatch1.ElapsedMilliseconds);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.