public void Spi_Reader_V5_dir_32k() { using (TextReader rdr = new StreamReader(@"c:\temp\allc.tsv", detectEncodingFromByteOrderMarks: true)) { var csvrdr = new Spi.CsvReader5(rdr, '\t', buffersize: 32 * 1024); while (csvrdr.Read()) { } } }
//[Benchmark] public void Spi_Reader_V4_5MB_quoted_64k() { using (TextReader rdr = new StreamReader(@"c:\temp\2.csv", detectEncodingFromByteOrderMarks: true)) { var csvrdr = new Spi.CsvReader5(rdr, ';', buffersize: 64 * 1024); while (csvrdr.Read()) { } } }
//[Benchmark] public void Spi_Reader_V4_dir_quoted_4k() { using (TextReader rdr = new StreamReader(@"c:\temp\allc_quoted.csv", detectEncodingFromByteOrderMarks: true)) { var csvrdr = new Spi.CsvReader5(rdr, ','); while (csvrdr.Read()) { } } }
static void Main(string[] args) { string delim = args[0]; string filename = args[1]; using (TextReader r1 = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read), detectEncodingFromByteOrderMarks: true)) using (TextReader r2 = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read), detectEncodingFromByteOrderMarks: true)) { var spi = new Spi.CsvReader5(r1, delim[0], buffersize: 64 * 1024); var gegner = new NReco.Csv.NRecoCsvReader(r2, delim) { TrimFields = false, BufferSize = 64 * 1024 }; int record = 0; try { for (; ;) { if (!spi.Read() | !gegner.Read()) { break; } ++record; if (spi.FieldCount != gegner.FieldsCount) { Console.WriteLine($"diff fieldcount - record: {record}\tfields: spi {spi.FieldCount}/{gegner.FieldsCount}"); } for (int i = 0; i < spi.FieldCount; ++i) { string s = spi[i].ToString(); string g = gegner[i]; if (String.CompareOrdinal(s, g) != 0) { Console.WriteLine($"--- {record} ---\ndiff s: [{s}]\ndiff g: [{g}]\n--- {record} ---"); } } //spi.PrintDebugInfo(); } } catch (Exception ex) { Console.WriteLine($"records parsed: {record}\nException: {ex.Message}"); spi.PrintDebugInfo(); } Console.WriteLine($"compared {record} records"); } }
private List <string[]> RunCsvReader(TextReader r, int buffersize = 1024, char delim = ',') { List <string[]> data = new List <string[]>(); using (r) { var csvrdr = new Spi.CsvReader5(r, delim, buffersize); while (csvrdr.Read()) { List <string> row = new List <string>(); for (int i = 0; i < csvrdr.FieldCount; ++i) { row.Add(csvrdr[i].ToString()); } data.Add(row.ToArray()); } } return(data); }