예제 #1
0
        /// <summary>
        /// The begin test.
        /// </summary>
        /// <remarks>http://wintersun.cnblogs.com/</remarks>
        private static void BeginTest()
        {
            var sb         = new StringBuilder();
            var testmodule = new ServiceLocatorConfig();
            List <IPerformanceTest> genericInstances = testmodule.GenericOverload_GetAllInstances();
            //Default dal
            string testSuitNames = "SqlClient(SN), NHibernateV1(NH), LinqToEntity(LE), LinqToSql(LQ)";

            var namelist = new List <string>();

            // for initial
            if (genericInstances != null)
            {
                genericInstances.ForEach(
                    tp =>
                {
                    tp.FetchSingleTest(1);
                    tp.FetchAllTest(1);
                    tp.WriteTest(1);
                    namelist.Add(tp.GetType().Name);
                });
            }

            testSuitNames = string.Join(" , ", namelist.ToArray());

            // repeat times
            var testmoduleconfig = (IDictionary)ConfigurationManager.GetSection("testmodule");
            var repeatTimestr    = (string)testmoduleconfig["repeatTimes"];

            int[] repeatTimes = new List <string>(repeatTimestr.Split(',')).ConvertAll(t => int.Parse(t)).ToArray();

            // string blocknames = "ADO.NET   ,     NH,     LE,     LQ    ";

            // sb.AppendLine(testSuitNames);
            // test fetch single performance
            TestFetchSinglePerformance(sb, genericInstances, testSuitNames, repeatTimes);

            sb.AppendLine();

            // test fetch all performance
            TestFetchAllPerformance(sb, genericInstances, repeatTimes);

            // test write performance
            TestWritePerformance(sb, genericInstances, repeatTimes);

            OutputToFile(sb);
        }
        /// <summary>
        /// The begin test.
        /// </summary>
        /// <remarks>http://wintersun.cnblogs.com/</remarks>
        private static void BeginTest()
        {
            var sb = new StringBuilder();
            var testmodule = new ServiceLocatorConfig();
            List<IPerformanceTest> genericInstances = testmodule.GenericOverload_GetAllInstances();
            string testSuitNames = "SqlClient(SN), NHibernateV1(NH), LinqToEntity(LE), LinqToSql(LQ)";

            var namelist = new List<string>();

            // for initial
            if (genericInstances != null)
            {
                genericInstances.ForEach(
                    tp =>
                        {
                            tp.FetchSingleTest(1);
                            tp.FetchAllTest(1);
                            tp.WriteTest(1);
                            namelist.Add(tp.GetType().Name);
                        });
            }

            testSuitNames = string.Join(" , ", namelist.ToArray());

            // repeat times
            var testmoduleconfig = (IDictionary)ConfigurationManager.GetSection("testmodule");
            var repeatTimestr = (string)testmoduleconfig["repeatTimes"];

            int[] repeatTimes = new List<string>(repeatTimestr.Split(',')).ConvertAll(t => int.Parse(t)).ToArray();

            // string blocknames = "ADO.NET   ,     NH,     LE,     LQ    ";

            // sb.AppendLine(testSuitNames);
            // test fetch single performance
            sb.AppendLine(string.Format("Compare {0} performance", "fetch single"));
            sb.AppendLine(testSuitNames);

            for (int i = 0; i < repeatTimes.Length; ++i)
            {
                sb.AppendLine();
                sb.AppendLine(string.Format("Repeat Time = {0}", repeatTimes[i]));

                genericInstances.ForEach(
                    tp =>
                        {
                            sb.Append(tp.FetchSingleTest(repeatTimes[i]));
                            sb.Append("\t");
                        });
                sb.AppendLine();
            }

            sb.AppendLine();

            // test fetch all performance
            sb.AppendLine(string.Format("Compare  {0} performance of", "fetch all"));
            for (int i = 0; i < repeatTimes.Length; ++i)
            {
                sb.AppendLine();
                sb.AppendLine(string.Format("Repeat Time = {0}", repeatTimes[i]));
                genericInstances.ForEach(
                    tp =>
                        {
                            sb.Append(tp.FetchAllTest(repeatTimes[i]));
                            sb.Append("\t");
                        });

                sb.AppendLine();
            }

            sb.AppendLine();

            // test write performance
            sb.AppendLine(string.Format("Compare  {0}  performance of {0}", "write"));
            for (int i = 0; i < repeatTimes.Length; ++i)
            {
                sb.AppendLine();
                sb.AppendLine(string.Format("Repeat Time = {0}", repeatTimes[i]));
                genericInstances.ForEach(
                    tp =>
                        {
                            sb.Append(tp.WriteTest(repeatTimes[i]));
                            sb.Append("\t");
                        });
                sb.AppendLine();
            }

            sb.AppendLine();

            OutputToFile(sb);
        }