コード例 #1
0
        static void Main(string[] args)
        {
            const string TestFile1 = @"..\..\test1.csv";
            const string TestFile2 = @"..\..\test2.csv";
            const string TestFile3 = @"..\..\test3.csv";

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            if (args.Length > 0)
            {
                if (args.Length == 1)
                {
                    string s = args[0].ToUpper();

                    switch (s)
                    {
                    case "CSVREADER":
                        CsvReaderBenchmark.Run(TestFile3);
                        return;

                    case "OLEDB":
                        OleDbBenchmark.Run(TestFile3);
                        return;

                    case "REGEX":
                        RegexBenchmark.Run(TestFile3);
                        return;
                    }
                }

                Console.WriteLine("Possible values : CsvReader, OleDb, Regex");
                return;
            }

            const int Field    = 72;
            long      fileSize = new System.IO.FileInfo(TestFile2).Length / 1024 / 1024;

            CachedCsvReader csv;

            long   start;
            long   end;
            long   frequency;
            long   clocks;
            double time;
            double rate;

            QueryPerformanceFrequency(out frequency);

            for (int i = 1; i < 4; i++)
            {
                Console.WriteLine("Test pass #{0} - All fields\n", i);

                QueryPerformanceCounter(out start);
                CsvReaderBenchmark.Run(TestFile2);
                QueryPerformanceCounter(out end);
                GetStats(start, end, frequency, fileSize, out clocks, out time, out rate);
                Console.WriteLine("CsvReader - No cache :\t\t {0} clocks, {1:f4} sec., {2:f4} MB/sec.", clocks, time, rate);
                GC.Collect();

                QueryPerformanceCounter(out start);
                csv = CachedCsvReaderBenchmark.Run1(TestFile2);
                QueryPerformanceCounter(out end);
                GetStats(start, end, frequency, fileSize, out clocks, out time, out rate);
                Console.WriteLine("CachedCsvReader - Run 1 :\t {0} clocks, {1:f4} sec., {2:f4} MB/sec.", clocks, time, rate);
                GC.Collect();

                QueryPerformanceCounter(out start);
                CachedCsvReaderBenchmark.Run2(csv);
                QueryPerformanceCounter(out end);
                GetStats(start, end, frequency, fileSize, out clocks, out time, out rate);
                Console.WriteLine("CachedCsvReader - Run 2 :\t {0} clocks, {1:f4} sec., {2:f4} MB/sec.", clocks, time, rate);
                csv = null;
                GC.Collect();

                QueryPerformanceCounter(out start);
                OleDbBenchmark.Run(TestFile2);
                QueryPerformanceCounter(out end);
                GetStats(start, end, frequency, fileSize, out clocks, out time, out rate);
                Console.WriteLine("OleDb :\t\t\t\t {0} clocks, {1:f4} sec., {2:f4} MB/sec.", clocks, time, rate);

                QueryPerformanceCounter(out start);
                RegexBenchmark.Run(TestFile2);
                QueryPerformanceCounter(out end);
                GetStats(start, end, frequency, fileSize, out clocks, out time, out rate);
                Console.WriteLine("Regex :\t\t\t\t {0} clocks, {1:f4} sec., {2:f4} MB/sec.", clocks, time, rate);

                Console.WriteLine();

                Console.WriteLine("Test pass #{0} - Field #{1} (middle)\n", i, Field);

                QueryPerformanceCounter(out start);
                CsvReaderBenchmark.Run(TestFile2, Field);
                QueryPerformanceCounter(out end);
                GetStats(start, end, frequency, fileSize, out clocks, out time, out rate);
                Console.WriteLine("CsvReader - No cache :\t\t {0} clocks, {1:f4} sec., {2:f4} MB/sec.", clocks, time, rate);
                GC.Collect();

                QueryPerformanceCounter(out start);
                csv = CachedCsvReaderBenchmark.Run1(TestFile2, Field);
                QueryPerformanceCounter(out end);
                GetStats(start, end, frequency, fileSize, out clocks, out time, out rate);
                Console.WriteLine("CachedCsvReader - Run 1 :\t {0} clocks, {1:f4} sec., {2:f4} MB/sec.", clocks, time, rate);
                GC.Collect();

                QueryPerformanceCounter(out start);
                CachedCsvReaderBenchmark.Run2(Field, csv);
                QueryPerformanceCounter(out end);
                GetStats(start, end, frequency, fileSize, out clocks, out time, out rate);
                Console.WriteLine("CachedCsvReader - Run 2 :\t {0} clocks, {1:f4} sec., {2:f4} MB/sec.", clocks, time, rate);
                csv = null;
                GC.Collect();

                QueryPerformanceCounter(out start);
                OleDbBenchmark.Run(TestFile2, Field);
                QueryPerformanceCounter(out end);
                GetStats(start, end, frequency, fileSize, out clocks, out time, out rate);
                Console.WriteLine("OleDb :\t\t\t\t {0} clocks, {1:f4} sec., {2:f4} MB/sec.", clocks, time, rate);

                QueryPerformanceCounter(out start);
                RegexBenchmark.Run(TestFile2, Field);
                QueryPerformanceCounter(out end);
                GetStats(start, end, frequency, fileSize, out clocks, out time, out rate);
                Console.WriteLine("Regex :\t\t\t\t {0} clocks, {1:f4} sec., {2:f4} MB/sec.", clocks, time, rate);

                Console.WriteLine();
                Console.WriteLine();
            }

            Console.WriteLine("Done");
            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: MinuraIddamalgoda/VB2010
        static void Main(string[] args)
        {
            //const string TestFile1 = @"..\..\test1.csv";
            const string TestFile2 = @"..\..\test2.csv";
            const string TestFile3 = @"..\..\test3.csv";

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            if (args.Length > 0)
            {
                if (args.Length == 1)
                {
                    string s = args[0].ToUpper();

                    switch (s)
                    {
                    case "CSVREADER":
                        CsvReaderBenchmark.Run(TestFile3);
                        return;

                    case "OLEDB":
                        OleDbBenchmark.Run(TestFile3);
                        return;

                    case "REGEX":
                        RegexBenchmark.Run(TestFile3);
                        return;
                    }
                }

                Console.WriteLine("Possible values : CsvReader, OleDb, Regex");
                return;
            }

            const int Field    = 72;
            long      fileSize = new System.IO.FileInfo(TestFile2).Length / 1024 / 1024;

            for (int i = 1; i < 4; i++)
            {
                object csv;

                Console.WriteLine("Test pass #{0} - All fields\n", i);

                DoTest("CsvReader - No cache", fileSize, CsvReaderBenchmark.Run, TestFile2);
                csv = DoTest("CachedCsvReader - Run 1", fileSize, CachedCsvReaderBenchmark.Run1, TestFile2);
                DoTest("CachedCsvReader - Run 2", fileSize, CachedCsvReaderBenchmark.Run2, csv);
                DoTest("TextFieldParser", fileSize, TextFieldParserBenchmark.Run, TestFile2);
                DoTest("Regex", fileSize, RegexBenchmark.Run, TestFile2);

                // seems to not be working on Windows 7 with Office 2007 (and I'm not bothering to try to make it run on my machine)
                //DoTest("OleDb", fileSize, OleDbBenchmark.Run, TestFile2);

                Console.WriteLine();

                Console.WriteLine("Test pass #{0} - Field #{1} (middle)\n", i, Field);

                DoTest("CsvReader - No cache", fileSize, CsvReaderBenchmark.Run, TestFile2, Field);
                csv = DoTest("CachedCsvReader - Run 1", fileSize, CachedCsvReaderBenchmark.Run1, TestFile2, Field);
                DoTest("CachedCsvReader - Run 2", fileSize, CachedCsvReaderBenchmark.Run2, csv, Field);
                DoTest("TextFieldParser", fileSize, TextFieldParserBenchmark.Run, TestFile2, Field);
                DoTest("Regex", fileSize, RegexBenchmark.Run, TestFile2, Field);

                // seems to not be working on Windows 7 with Office 2007 (and I'm not bothering to try to make it run on my machine)
                //DoTest("OleDb", fileSize, OleDbBenchmark.Run, TestFile2, Field);

                Console.WriteLine();
                Console.WriteLine();
            }

            Console.WriteLine("Done");
            Console.ReadLine();
        }