Ejemplo n.º 1
0
        public void TestGetter()
        {
            ReflectionTest <Guid>             rt   = new ReflectionTest <Guid>(Guid.NewGuid());
            Func <ReflectionTest <Guid>, int> getA = Reflection.GetGetter <ReflectionTest <Guid>, int>("A");

            Assert.AreEqual(getA(rt), 3);

            Func <ReflectionTest <Guid>, int> getB = Reflection.GetGetter <ReflectionTest <Guid>, int>("B");

            Assert.AreEqual(getB(rt), 5);

            Func <ReflectionTest <Guid>, ReflectionTest <Guid> > getLast =
                Reflection.GetGetter <ReflectionTest <Guid>, ReflectionTest <Guid> >("Last");

            Assert.AreEqual(getLast(rt), rt);

            // Should throw exception - no getter for C
            Func <ReflectionTest <Guid>, int> getC = Reflection.GetGetter <ReflectionTest <Guid>, int>("C");
        }
Ejemplo n.º 2
0
        static void GetValueToStringTest()
        {
            ReflectionTest test = new ReflectionTest();

            test.Set = new HashSet <string> {
                "1", "2"
            };
            test.Dict = new Dictionary <string, string>
            {
                ["1"] = "1",
                ["2"] = "2",
                ["3"] = null,
            };
            Console.WriteLine(test.Dict.ContainsKey("3"));
            test.Array   = new string[] { "1", "2" };
            test.Char    = '1';
            test.Boolean = true;
            test.Enum    = ReflectionEnum.One;
            var properties = test.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty);

            Console.WriteLine(JsonConvert.SerializeObject(test));
            Console.WriteLine("---------------");

            //object property = setProperty.GetValue(test);

            foreach (var property in properties)
            {
                var    type        = property?.GetValue(test)?.GetType();
                string propertyStr = ConvertPropertyValueToString(property?.GetValue(test));

                Console.WriteLine(type);
                Console.WriteLine(property?.GetValue(test)?.ToString());
                Console.WriteLine(propertyStr);
                Console.WriteLine("-------------------");
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("欢迎来到.net高级班vip课程,今天是Eleven老师为大家带来的反射Reflection");
                #region Common
                //DBHelper dbHelper = new DBHelper();
                //dbHelper.Id = 1;
                //dbHelper.Name = "仗劍走天涯";
                //dbHelper.Query();
                #endregion Common

                #region 反射加载dll,读取module、类、方法、特性
                Assembly assembly  = Assembly.Load("Ruanmou.DB.Sqlserver");                                                                                            //1 动态加载     默认加载当前路径的dll文件,不需要后缀
                Assembly assembly1 = Assembly.LoadFile(@"E:\online7\20160928Advanced7Course2Reflection\MyReflection\MyReflection\bin\Debug\Ruanmou.DB.Sqlserver.dll"); // 必须是完整路径
                Assembly assembly2 = Assembly.LoadFrom("Ruanmou.DB.Sqlserver.dll");                                                                                    // 可以是当前路径  也可以是完整路径

                Console.WriteLine("************GetModules**********");
                foreach (var item in assembly.GetModules())
                {
                    Console.WriteLine(item.FullyQualifiedName);
                }
                foreach (var item in assembly.GetTypes())
                {
                    Console.WriteLine(item.FullName);
                }
                Type typeDBHelper = assembly.GetType("Ruanmou.DB.Sqlserver.DBHelper");//2 获取类型 (获取类型信息的方式不止一个)
                foreach (var item in typeDBHelper.GetConstructors())
                {
                    Console.WriteLine(item.Name);
                }
                foreach (var item in typeDBHelper.GetProperties())
                {
                    Console.WriteLine(item.Name);
                }
                foreach (var item in typeDBHelper.GetMethods())
                {
                    Console.WriteLine(item.Name);
                }
                foreach (var item in typeDBHelper.GetFields())
                {
                    Console.WriteLine(item.Name);
                }

                #endregion

                #region 反射创建对象,反射+简单工厂+配置文件  选修:破坏单例 创建泛型
                Console.WriteLine("**************************************************");
                {
                    object    oDBHelper          = Activator.CreateInstance(typeDBHelper);//3 创建对象
                    IDBHelper dbHelperReflection = (IDBHelper)oDBHelper;
                    dbHelperReflection.Query();

                    IDBHelper dbHelperFactory = SimpleFactory.CreateDBHelper();
                    dbHelperFactory.Query();
                }
                {
                    Console.WriteLine("**************带参数的构造函数****************");
                    Type typeTest = assembly.GetType("Ruanmou.DB.Sqlserver.ReflectionTest");//2 获取类型 (获取类型信息的方式不止一个)
                    foreach (var item in typeTest.GetConstructors())
                    {
                        Console.WriteLine(item.Name);
                    }
                    Activator.CreateInstance(typeTest);
                    Activator.CreateInstance(typeTest, "demon");
                    Activator.CreateInstance(typeTest, 11, "限量版(397-限量版)");
                    //Activator.CreateInstance(typeTest, "限量版(397-限量版)", 11);


                    Type typeSingleton = assembly.GetType("Ruanmou.DB.Sqlserver.Singleton");
                    Activator.CreateInstance(typeSingleton, true);
                    Activator.CreateInstance(typeSingleton, true);

                    Type typeGeneric = assembly.GetType("Ruanmou.DB.Sqlserver.GenericClass`1");
                    typeGeneric = typeGeneric.MakeGenericType(typeof(int));
                    Activator.CreateInstance(typeGeneric);
                }

                #region 反射调用实例方法、静态方法、重载方法 选修:调用私有方法 调用泛型方法
                {
                    Console.WriteLine("**************反射调用实例方法****************");
                    Type   typeTest = assembly.GetType("Ruanmou.DB.Sqlserver.ReflectionTest");//2 获取类型 (获取类型信息的方式不止一个)
                    object oTest    = Activator.CreateInstance(typeTest);

                    foreach (var item in typeTest.GetMethods())
                    {
                        Console.WriteLine(item.Name);
                    }
                    {
                        MethodInfo method = typeTest.GetMethod("Show1");
                        method.Invoke(oTest, null);
                    }
                    {
                        MethodInfo method = typeTest.GetMethod("Show2");
                        method.Invoke(oTest, new object[] { 11 });
                    }
                    {
                        MethodInfo method = typeTest.GetMethod("ShowStatic");
                        method.Invoke(null, new object[] { "KOBE→Bryant" });
                    }
                    {
                        MethodInfo method = typeTest.GetMethod("Show3", new Type[] { });
                        method.Invoke(oTest, null);
                    }
                    {
                        MethodInfo method = typeTest.GetMethod("Show3", new Type[] { typeof(int) });
                        method.Invoke(oTest, new object[] { 11 });
                    }
                    {
                        MethodInfo method = typeTest.GetMethod("Show3", new Type[] { typeof(string) });
                        method.Invoke(oTest, new object[] { "限量版(397-限量版)" });
                    }
                    {
                        MethodInfo method = typeTest.GetMethod("Show3", new Type[] { typeof(string), typeof(int) });
                        method.Invoke(oTest, new object[] { "书呆熊@拜仁", 22 });
                    }
                    {
                        MethodInfo method = typeTest.GetMethod("Show3", new Type[] { typeof(int), typeof(string) });
                        method.Invoke(oTest, new object[] { 33, "不懂微软" });
                    }
                    {
                        MethodInfo method = typeTest.GetMethod("Show4", BindingFlags.Instance | BindingFlags.NonPublic);
                        method.Invoke(oTest, new object[] { "有木有" });
                    }
                    {
                        MethodInfo method = typeTest.GetMethod("ShowGeneric");
                        method = method.MakeGenericMethod(typeof(string));
                        method.Invoke(oTest, new object[] { "有木有" });
                    }
                }
                #endregion

                //DBHelper dbHelperReflection1 = oDBHelper as DBHelper;
                //dbHelperReflection1.Query();

                //oDBHelper.

                #endregion

                #region 反射字段和属性,分别获取值和设置值
                {
                    Console.WriteLine("**************反射字段和属性****************");
                    ReflectionTest test = new ReflectionTest();
                    test.Id   = 11;
                    test.Name = "妙为";

                    Type   typeTest = assembly.GetType("Ruanmou.DB.Sqlserver.ReflectionTest");
                    object oTest    = Activator.CreateInstance(typeTest);
                    //foreach (var item in typeTest.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public))
                    //{
                    //    Console.WriteLine(item.Name);
                    //}
                    foreach (var prop in typeTest.GetProperties())
                    {
                        Console.WriteLine(prop.GetValue(oTest));
                        Console.WriteLine(prop.Name);
                        if (prop.Name.Equals("Id"))
                        {
                            prop.SetValue(oTest, 22);
                        }
                        else if (prop.Name.Equals("Name"))
                        {
                            prop.SetValue(oTest, "Bond(331-object)");
                        }

                        Console.WriteLine(prop.GetValue(oTest));
                    }
                }


                #endregion


                #region 反射的好处和局限   好处就是动态
                {
                    Stopwatch watch = new Stopwatch();
                    watch.Start();
                    for (int i = 0; i < 100000; i++)
                    {
                        DBHelper dbHelper = new DBHelper();
                        dbHelper.Id   = 1;
                        dbHelper.Name = "仗劍走天涯";
                        dbHelper.Query();
                    }
                    watch.Stop();
                    Console.WriteLine("普通方式花费{0}ms", watch.ElapsedMilliseconds);
                }
                {
                    Stopwatch watch = new Stopwatch();
                    watch.Start();
                    for (int i = 0; i < 100000; i++)
                    {
                        Assembly assemblyTest = Assembly.Load("Ruanmou.DB.Sqlserver");

                        Type   typeTest = assemblyTest.GetType("Ruanmou.DB.Sqlserver.DBHelper");
                        object oTest    = Activator.CreateInstance(typeTest);

                        foreach (var prop in typeTest.GetProperties())
                        {
                            if (prop.Name.Equals("Id"))
                            {
                                prop.SetValue(oTest, 1);
                            }
                            else if (prop.Name.Equals("Name"))
                            {
                                prop.SetValue(oTest, "仗劍走天涯");
                            }
                        }
                        MethodInfo method = typeTest.GetMethod("Query");
                        method.Invoke(oTest, null);
                    }
                    watch.Stop();
                    Console.WriteLine("反射方式花费{0}ms", watch.ElapsedMilliseconds);
                }
                #endregion
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.Read();
        }
Ejemplo n.º 4
0
    /**
     * main.
     *
     * @param args
     */
    public static void main(string[] args)
    {
        int nbTests             = (args != null && args.Length >= 1) ? int.Parse(args[0]) : NB_TESTS;
        int nbOfExclusionMinMax = (args != null && args.Length >= 2) ? int.Parse(args[1]) : NB_OF_EXCLUSION_MIN_MAX;

        List <long> executionTimes = new List <long>(nbTests);


        for (int i = nbTests; i != 0; i--)
        {
            executionTimes.Add(ReflectionTest.testCreationReflectionClassWith1String());
        }
        executionTimes.Sort();
        Console.WriteLine("[ReflectionTest], Creation of String " + NB_CREATION_TESTS + ",, average time,"
                          + averageTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax) + ", min time," + executionTimes[0] + ", max time," + executionTimes[executionTimes.Count - 1]
                          + ", relative deviation time," + relativeDeviationTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax));
        executionTimes.Clear();

        for (int i = nbTests; i != 0; i--)
        {
            executionTimes.Add(ReflectionTest.testCreationReflectionClassWith1StringWithReflection());
        }
        executionTimes.Sort();
        Console.WriteLine("[ReflectionTest], Creation of String Wihh Reflection " + NB_CREATION_TESTS + ",, average time,"
                          + averageTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax) + ", min time," + executionTimes[0] + ", max time," + executionTimes[executionTimes.Count - 1]
                          + ", relative deviation time," + relativeDeviationTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax));
        executionTimes.Clear();

        for (int i = nbTests; i != 0; i--)
        {
            executionTimes.Add(ReflectionTest.testGetterReflectionClassWith1String());
        }
        executionTimes.Sort();
        Console.WriteLine("[ReflectionTest], Getter of ReflectionClassWith1String() test=" + NB_GETTER_TESTS + ",, average time,"
                          + averageTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax) + ", min time," + executionTimes[0] + ", max time," + executionTimes[executionTimes.Count - 1]
                          + ", relative deviation time," + relativeDeviationTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax));
        executionTimes.Clear();

        for (int i = nbTests; i != 0; i--)
        {
            executionTimes.Add(ReflectionTest.testGetterReflectionClassWith1StringWithReflection());
        }
        executionTimes.Sort();
        Console.WriteLine("[ReflectionTest], Getter of ReflectionClassWith1String() with Reflection test=" + NB_GETTER_TESTS + ",, average time,"
                          + averageTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax) + ", min time," + executionTimes[0] + ", max time," + executionTimes[executionTimes.Count - 1]
                          + ", relative deviation time," + relativeDeviationTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax));
        executionTimes.Clear();


        for (int i = nbTests; i != 0; i--)
        {
            executionTimes.Add(ReflectionTest.testSetterReflectionClassWith1String());
        }
        executionTimes.Sort();
        Console.WriteLine("[ReflectionTest], Setter of ReflectionClassWith1String() test=" + NB_SETTER_TESTS + ",, average time,"
                          + averageTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax) + ", min time," + executionTimes[0] + ", max time," + executionTimes[executionTimes.Count - 1]
                          + ", relative deviation time," + relativeDeviationTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax));
        executionTimes.Clear();

        for (int i = nbTests; i != 0; i--)
        {
            executionTimes.Add(ReflectionTest.testSetterReflectionClassWith1StringWithReflection());
        }
        executionTimes.Sort();
        Console.WriteLine("[ReflectionTest], Setter of ReflectionClassWith1String() with Reflection test=" + NB_SETTER_TESTS + ",, average time,"
                          + averageTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax) + ", min time," + executionTimes[0] + ", max time," + executionTimes[executionTimes.Count - 1]
                          + ", relative deviation time," + relativeDeviationTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax));
        executionTimes.Clear();

        for (int i = nbTests; i != 0; i--)
        {
            executionTimes.Add(ReflectionTest.testInvokeOfAStaticMethod());
        }
        executionTimes.Sort();
        Console.WriteLine("[ReflectionTest], Invoke Of A Static Method " + NB_STATIC_REFLECTION_TESTS
                          + " ReflectionInvokeImpl.echoStatic(\"\").length(),, average time,"
                          + averageTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax) + ", min time," + executionTimes[0] + ", max time," + executionTimes[executionTimes.Count - 1]
                          + ", relative deviation time," + relativeDeviationTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax));
        executionTimes.Clear();

        for (int i = nbTests; i != 0; i--)
        {
            executionTimes.Add(ReflectionTest.testInvokeOfAStaticMethodWithReflection());
        }
        executionTimes.Sort();
        Console.WriteLine("[ReflectionTest], Invoke Of A Static Method With Reflection " + NB_STATIC_REFLECTION_TESTS
                          + " ReflectionInvokeImpl.echoStatic(\"\").length(),, average time,"
                          + averageTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax) + ", min time," + executionTimes[0] + ", max time," + executionTimes[executionTimes.Count - 1]
                          + ", relative deviation time," + relativeDeviationTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax));
        executionTimes.Clear();


        for (int i = nbTests; i != 0; i--)
        {
            executionTimes.Add(ReflectionTest.testInvokeOfAnInstanceMethodWithGetInstanceVariableWithoutInterface());
        }
        executionTimes.Sort();
        Console.WriteLine("[ReflectionTest], Invoke Of An Instance Method With Get Instance Variable Without Interface " + NB_INSTANCE_REFLECTION_TESTS
                          + " invoke.echoWithGetVariable().length()  ,, average time,"
                          + averageTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax) + ", min time," + executionTimes[0] + ", max time," + executionTimes[executionTimes.Count - 1]
                          + ", relative deviation time," + relativeDeviationTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax));
        executionTimes.Clear();

        for (int i = nbTests; i != 0; i--)
        {
            executionTimes.Add(ReflectionTest.testInvokeOfAnInstanceMethodWithGetInstanceVariableWithoutInterfaceWithReflection());
        }
        executionTimes.Sort();
        Console.WriteLine("[ReflectionTest], Invoke Of An Instance Method With Get Instance Variable Without Interface With Reflection "
                          + NB_INSTANCE_REFLECTION_TESTS + " invoke.echoWithSetVariable().length()  ,, average time,"
                          + averageTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax) + ", min time," + executionTimes[0] + ", max time," + executionTimes[executionTimes.Count - 1]
                          + ", relative deviation time," + relativeDeviationTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax));
        executionTimes.Clear();


        for (int i = nbTests; i != 0; i--)
        {
            executionTimes.Add(ReflectionTest.testInvokeOfAnInstanceMethodWithSetInstanceVariableWithoutInterface());
        }
        executionTimes.Sort();
        Console.WriteLine("[ReflectionTest], Invoke Of An Instance Method With Set Instance Variable Without Interface " + NB_INSTANCE_REFLECTION_TESTS
                          + " invoke.echoWithSetVariable(\"1\").length()  ,, average time,"
                          + averageTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax) + ", min time," + executionTimes[0] + ", max time," + executionTimes[executionTimes.Count - 1]
                          + ", relative deviation time," + relativeDeviationTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax));
        executionTimes.Clear();

        for (int i = nbTests; i != 0; i--)
        {
            executionTimes.Add(ReflectionTest.testInvokeOfAnInstanceMethodWithSetInstanceVariableWithoutInterfaceWithReflection());
        }
        executionTimes.Sort();
        Console.WriteLine("[ReflectionTest], Invoke Of An Instance Method With Set Instance Variable Without Interface With Reflection "
                          + NB_INSTANCE_REFLECTION_TESTS + " invoke.echoWithSetVariable(\"1\").length()  ,, average time,"
                          + averageTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax) + ", min time," + executionTimes[0] + ", max time," + executionTimes[executionTimes.Count - 1]
                          + ", relative deviation time," + relativeDeviationTimeWithoutMinMax(executionTimes, nbOfExclusionMinMax));
        executionTimes.Clear();
    }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //FQuery.Tools.FQuery query = new FQuery.Tools.FQuery();
            //IEnity entity = query.GetScheme("Clients");
            //entity.Field["name"] = "ss";
            //entity.Field["id"] = "1";
            //entity.Insert();
            //entity.Update();
            //entity.Delete();
            //List<IEnity> list = query.Form("select * from clients").ToList<IEnity>() ;
            //foreach (IEnity item in list)
            //{
            //    item.Field[""] = "";
            //}

            DataTable dt = new DataTable();
            dt.Columns.Add("ID");
            dt.Columns.Add("Name");
            dt.Columns.Add("a");
            dt.Columns.Add("a1");
            dt.Columns.Add("a2");
            dt.Columns.Add("a3");
            dt.Columns.Add("a4");
            dt.Columns.Add("a5");
            dt.Columns.Add("a6");
            dt.Columns.Add("a7");
            dt.Columns.Add("a8");
            dt.Columns.Add("a9");
            for(int i=0;i<1000000;i++)
            {
                DataRow dr =dt.NewRow();
                dr[0]=Guid.NewGuid();
                dr[1]="aasdddddddddddddddddddddddddddddddddddddddddaa";
                dr[2] = "aadddddddddddddddddddddddddddddddaaaa";
                dr[3] = "aaddddddddddddddddddddddddddaaaa";
                dr[4] = "aaaddddddddddddddddddddddddddddddddddddddddaaa";
                dr[5] = "aaadddddddddddddddddaaa";
                dr[6] = "aaaddddddddddddddaaa";
                dr[7] = "aaaddddddddddddddddddddddddddddddddddddddddddddddddddddaaa";
                dr[8] = "aaadddddddddddddddddddddddaaa";
                dr[9] = "aaadddddddddddddddddddaaa";
                dr[10] = "aadddddddddddddddddddddddddaaaa";
                dr[11] = "aaadddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddaaa";
                dt.Rows.Add(dr);
            }
            ReflectionTest test = new ReflectionTest();
            Stopwatch stop = new Stopwatch();
            stop.Start();
            List<TestEntiy> list = test.ToList<TestEntiy>(dt);
            stop.Stop();
            double time1 = stop.Elapsed.TotalSeconds;
            stop.Reset();
            Console.WriteLine("方法:ToList耗时-" + time1.ToString());
            stop.Start();
            List<TestEntiy> list2 = test.ToList_Direct(dt);
            stop.Stop();
            Console.WriteLine("方法:ToList_Direct耗时-" + stop.Elapsed.TotalSeconds.ToString());
            stop.Reset();
            stop.Start();
            List<TestEntiy> list1 = test.ToList_Extend<TestEntiy>(dt);
            stop.Stop();
            double time2 = stop.Elapsed.TotalSeconds;
            Console.WriteLine("方法:ToList_Extend耗时-" + time2.ToString());
            stop.Reset();
            stop.Start();
            List<TestEntiy> list3 = test.ToList_Emit<TestEntiy>(dt);
            stop.Stop();
            Console.WriteLine("方法:ToList_Emit耗时:" + stop.Elapsed.TotalSeconds.ToString());
            stop.Reset();
            stop.Start();
            List<TestEntiy> list4 = test.ToList_Emit<TestEntiy>(dt);
            stop.Stop();
            Console.WriteLine("方法:第二次调用ToList_Emit耗时:" + stop.Elapsed.TotalSeconds.ToString());
            //stop.Reset();
            //stop.Start();
            //List<TestEntiy> list5 = test.ToList_Emit2<TestEntiy>(dt);
            //stop.Stop();
            //Console.WriteLine("方法:ToList_Emit2耗时:" + stop.Elapsed.TotalSeconds.ToString());

            //stop.Reset();
            //stop.Start();
            //List<TestEntiy> list6 = test.ToList_Emit2<TestEntiy>(dt);
            //stop.Stop();
            //Console.WriteLine("方法:第二次调用ToList_Emit2耗时:" + stop.Elapsed.TotalSeconds.ToString());
            //stop.Reset();
            //stop.Start();
            //List<TestEntiy> list7 = test.ToList_Emit2<TestEntiy>(dt);
            //stop.Stop();
            //Console.WriteLine("方法:第三次调用ToList_Emit2耗时:" + stop.Elapsed.TotalSeconds.ToString());

            //stop.Reset();
            //stop.Start();
            //List<TestEntiy> list8 = test.ToList_Emit2<TestEntiy>(dt);
            //stop.Stop();
            //Console.WriteLine("方法:第四次调用ToList_Emit2耗时:" + stop.Elapsed.TotalSeconds.ToString());

            EntityExtend ee = new EntityExtend();
            stop.Reset();
            stop.Start();
            var a= ee.ToList<TestEntiy>(dt);
            stop.Stop();
            Console.WriteLine("方法:第一次调用ToList耗时:" + stop.Elapsed.TotalSeconds.ToString());
            stop.Reset();
            stop.Start();
             a = ee.ToList<TestEntiy>(dt);
            stop.Stop();
            Console.WriteLine("方法:第二次调用ToList耗时:" + stop.Elapsed.TotalSeconds.ToString());
            stop.Reset();
            stop.Start();
            a = ee.ToList<TestEntiy>(dt);
            stop.Stop();
            Console.WriteLine("方法:第三次调用ToList耗时:" + stop.Elapsed.TotalSeconds.ToString());
            stop.Reset();
            stop.Start();
             a = ee.ToList<TestEntiy>(dt);
            stop.Stop();
            Console.WriteLine("方法:第四次调用ToList耗时:" + stop.Elapsed.TotalSeconds.ToString());
            stop.Reset();
            stop.Start();
             a = ee.ToList<TestEntiy>(dt);
            stop.Stop();
            Console.WriteLine("方法:第五次调用ToList耗时:" + stop.Elapsed.TotalSeconds.ToString());

            Console.Read();
        }
Ejemplo n.º 6
0
    public static void Main(string[] args)
    {
        StreamWriter sw = null;

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("getter-setter-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        GetterSetterTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("getter-setter-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        GetterSetterTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("invoke-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        InvokeTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("invoke-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        InvokeTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("creation-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        CreationTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("creation-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        CreationTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("collection-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        CollectionTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("collection-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        CollectionTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("arithmetic-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        ArithmeticTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("arithmetic-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        ArithmeticTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("threading-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        ThreadingTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("threading-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        ThreadingTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("timing-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        TimingTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("timing-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        TimingTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("autoboxing-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        AutoboxingTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("autoboxing-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        AutoboxingTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("file-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        FileTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("file-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        FileTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("exception-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        ExceptionTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("exception-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        ExceptionTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("recursive-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        RecursiveTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("recursive-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        RecursiveTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("stringconcat-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        StringConcatTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("stringconcat-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        StringConcatTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("nestedloops-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        NestedLoopsTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("nestedloops-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        NestedLoopsTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("heap-sort-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        HeapSortTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("heap-sort-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        HeapSortTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("matrix-multiply-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        MatrixMultiplyTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("matrix-multiply-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        MatrixMultiplyTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("reflection-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        ReflectionTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("reflection-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        ReflectionTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("enum-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        EnumTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("enum-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        EnumTest.main(ARGS);
        sw.Close();


        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("trigo-benchmark-csharp-firstinvoke.csv", FileMode.Create));
        Console.SetOut(sw);
        TrigoTest.main(ARGS);
        sw.Close();

        LaunchGcAndSleep();
        sw = new StreamWriter(new FileStream("trigo-benchmark-csharp.csv", FileMode.Create));
        Console.SetOut(sw);
        TrigoTest.main(ARGS);
        sw.Close();


        //TODO NetworkInvoke.main(ARGS);
    }