Example #1
0
        /// <summary>
        ///   Executes the provided <see cref="Action"/> several times to average out the time spent in execution.
        /// </summary>
        /// <param name="action">The action representing the test.</param>
        /// <param name="fieldType">The field type to test (Delimited or FixedWidth).</param>
        /// <param name="lngFileLength">The length of the file being parsed in bytes.</param>
        /// <param name="strTestName">The name of the test.</param>
        private static void _TestRunner(Action action, FieldType fieldType, long lngFileLength, string strTestName)
        {
            Stopwatch sw;
            double    dblAvgDuration;

            // Clear out the trash so as to minimize the likelyhood of the garbage being taken out during the tests.
            GC.Collect();
            GC.WaitForFullGCComplete();
            GC.WaitForPendingFinalizers();

            sw = Stopwatch.StartNew();

            for (int intTestIteration = 0; intTestIteration < PerformanceTests.ITERATIONS_OF_TESTS; ++intTestIteration)
            {
                action();
            }

            sw.Stop();

            dblAvgDuration = ((double)sw.ElapsedMilliseconds) / ((double)PerformanceTests.ITERATIONS_OF_TESTS);

            Console.WriteLine(string.Format("{0,-10} {1,21} - Avg. Time {2,10:#0.0} (ms) [{3,14}]",
                                            fieldType.ToString(),
                                            strTestName,
                                            dblAvgDuration,
                                            PerformanceTests._CalculateThroughput(lngFileLength, dblAvgDuration)));
        }
Example #2
0
        /// <summary>
        ///   Calculates the throughput by the length of the file and the average duration to parse it.
        /// </summary>
        /// <param name="lngFileLength">The length of the file in bytes.</param>
        /// <param name="dblAvgDuration">The average duration to parse the file.</param>
        /// <returns>The string represntation of the throughput.</returns>
        private static string _CalculateThroughput(long lngFileLength, double dblAvgDuration)
        {
            string strUnits;
            double dblUnscaledThroughput, dblScaledThroughput;

            // Multiply the length by 1000 change the units to seconds.
            dblUnscaledThroughput = (((double)lngFileLength) * 1000d) / dblAvgDuration;

            // Perform the scaling of the filelength.
            PerformanceTests._ScaleValue(dblUnscaledThroughput, out dblScaledThroughput, out strUnits);

            return(string.Format("{0,9:#0.000} {1}/s", dblScaledThroughput, strUnits));
        }
Example #3
0
        static void Main(string[] args)
        {
            long   lngFileLength;
            double dblScaledValue;
            string strRowsOfData, strUnits;

            Console.Write(string.Format("Number of iterations of data [1 iteration = {0} rows]: ", PerformanceTests.NUMBER_OF_ROWS_IN_DATA));
            strRowsOfData = Console.ReadLine();

            if ((strRowsOfData.Length < 1) || !int.TryParse(strRowsOfData, out PerformanceTests.RowsOfData) || (PerformanceTests.RowsOfData < 1))
            {
                Console.WriteLine();
                Console.WriteLine("Please supply a valid number.");
                Console.WriteLine();
                Console.WriteLine("<- Press Enter to Proceed ->");
                Console.ReadLine();
                return;
            }

            /////////////////////////
            // Performance Testing //
            /////////////////////////

            // Make sure the user wants to perform it, since it will be a
            // long running process.
            Console.Write(Environment.NewLine);
            Console.WriteLine("The following will generate performance information about the");
            Console.WriteLine("GenericParser class.");
            Console.Write(Environment.NewLine);

            Console.WriteLine("Executions for each test: {0}", PerformanceTests.ITERATIONS_OF_TESTS);
            Console.WriteLine("Rows of CSV Data:         {0}", PerformanceTests.RowsOfData * PerformanceTests.NUMBER_OF_ROWS_IN_DATA);
            Console.WriteLine("Rows of FixedWidth Data:  {0}", PerformanceTests.RowsOfData * PerformanceTests.NUMBER_OF_ROWS_IN_DATA);
            Console.Write(Environment.NewLine);

            Console.WriteLine("<- Press Enter to Proceed ->");
            Console.ReadLine();

            ///////////////////////////////////////////
            // Start executing the performance tests //
            ///////////////////////////////////////////

            PerformanceTests._GenerateSchemaFile();
            PerformanceTests._GenerateCsvData();

            lngFileLength = new FileInfo(CSV_DATA_FILE).Length;

            PerformanceTests._ScaleValue((double)lngFileLength, out dblScaledValue, out strUnits);
            Console.WriteLine("Size of Csv data file: {0,5:#0.00} {1}", dblScaledValue, strUnits);
            Console.WriteLine();

            PerformanceTests._TestRunner(new Action(PerformanceTests._TextDriverCsv), FieldType.Delimited, lngFileLength, "MS Text Driver");
            PerformanceTests._TestRunner(new Action(PerformanceTests._TextFieldParserCsv), FieldType.Delimited, lngFileLength, "MS Text Field Parser");
            PerformanceTests._TestRunner(new Action(PerformanceTests._CsvReader), FieldType.Delimited, lngFileLength, "CsvReader 3.7");
            PerformanceTests._TestRunner(new Action(PerformanceTests._GenericParser10Csv), FieldType.Delimited, lngFileLength, "GenericParser 1.0");
            PerformanceTests._TestRunner(new Action(PerformanceTests._GenericParser11Csv), FieldType.Delimited, lngFileLength, "GenericParser 1.1");

            Console.Write(Environment.NewLine);
            Console.WriteLine("============================================");
            Console.Write(Environment.NewLine);

            PerformanceTests._GenerateFixedWidthData();

            lngFileLength = new FileInfo(PerformanceTests.FW_DATA_FILE).Length;

            PerformanceTests._ScaleValue((double)lngFileLength, out dblScaledValue, out strUnits);
            Console.WriteLine("Size of FixedWidth data file: {0,5:#0.00} {1}", dblScaledValue, strUnits);
            Console.WriteLine();

            PerformanceTests._TestRunner(new Action(PerformanceTests._TextDriverFixedWidth), FieldType.FixedWidth, lngFileLength, "MS Text Driver");
            PerformanceTests._TestRunner(new Action(PerformanceTests._TextFieldParserFixedWidth), FieldType.FixedWidth, lngFileLength, "MS Text Field Parser");
            PerformanceTests._TestRunner(new Action(PerformanceTests._GenericParser10FixedWidth), FieldType.FixedWidth, lngFileLength, "GenericParser 1.0");
            PerformanceTests._TestRunner(new Action(PerformanceTests._GenericParser11FixedWidth), FieldType.FixedWidth, lngFileLength, "GenericParser 1.1");

            Console.Write(Environment.NewLine);
            Console.WriteLine("Completed Performance testing.");
            Console.Write(Environment.NewLine);
            Console.WriteLine("<- Press Enter to Exit ->");
            Console.ReadLine();

            // Cleanup the files we created.
            File.Delete(PerformanceTests.CSV_DATA_FILE);
            File.Delete(PerformanceTests.FW_DATA_FILE);
            File.Delete(PerformanceTests.SCHEMA_FILE);
        }