Last active
December 30, 2015 17:29
-
-
Save Ruszrok/7861319 to your computer and use it in GitHub Desktop.
Microsoft.VisualBasic.FileIO.TextFieldParser vs String.Split
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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