public void CanParseMultilineFieldsParseCustom()
        {
            var settings = new CsvSettings {
                Separator = ',', UseQuotes = true
            };

            List <string[]> data;

            using (var sr = new StreamReader(@"TestFiles\multline.csv")) data = settings.ParseCustom(sr).ToList();

            this.AssertDataEqual(_expectedData, data);
        }
Beispiel #2
0
        private static void PerfTestCsvParsers(int loops = 5)
        {
            // Prepare huge csv
            var mm = new MemoryStream();
            var sw = new StreamWriter(mm);

            GenerateCsv(20, 200000, sw);

            mm.Position = 0;
            var sr    = new StreamReader(mm, Encoding.UTF8, false, 1024 * 16, true);
            var count = 0;

            CsvSettings csvSettings = new CsvSettings(',');
            var         timer       = new LoopDiagnosticTimer();

            // Compare results of different parsers
            if (Param.Flag('C'))
            {
                var vb = csvSettings.ParseVB(sr).ToList();
                timer.Checkpoint($"VB.ToList()");
                mm.Position = 0;
                sr          = new StreamReader(mm, Encoding.UTF8, false, 1024 * 16, true);
                var custom = csvSettings.ParseCustom(sr).ToList();
                timer.Checkpoint($"ParseCustom.ToList()");

                if (custom.Count != vb.Count)
                {
                    Console.Error.WriteLine($"Error: VB rows={vb.Count} != Std rows={custom.Count}");
                }

                for (int i = 0; i < custom.Count; i++)
                {
                    if (custom[i].Length != vb[i].Length)
                    {
                        Console.Error.WriteLine($"Error (line {i}): VB columns={vb[i].Length} != Std columns={custom[i].Length}");
                    }

                    for (int c = 0; c < custom[i].Length; c++)
                    {
                        if (custom[i][c] != vb[i][c])
                        {
                            Console.Error.WriteLine($"Error (line {i}, column {c}): VB column='{vb[i][c]}' != Std column='{custom[i][c]}'");
                        }
                    }
                }

                timer.Checkpoint("Comparison");
            }

            for (int i = 0; i < loops; i++)
            {
                // VB is ten times slower
                mm.Position = 0;
                count       = 0;
                foreach (var line in csvSettings.ParseVB(sr))
                {
                    count++;
                }
                timer.Checkpoint($"VB");

                mm.Position = 0;
                sr          = new StreamReader(mm, Encoding.UTF8, false, 1024 * 16, true);
                count       = 0;
                foreach (var line in csvSettings.ParseCustom(sr))
                {
                    count++;
                }
                timer.Checkpoint($"ParseCustom");
            }

            Console.WriteLine(timer.LastCheckpoint($"End"));
        }