Пример #1
0
        static unsafe void Main(string[] args)
        {
            int count = 10000 * 1000;

            var sw = new Stopwatch();


            long p1   = 0;
            long p2   = 0;
            var  code = @"
	
    // [99 9 - 99 10]
    IL_0000: nop          

    // [100 13 - 100 23]
    IL_0001: ldc.i4.1     
    IL_0002: stloc.0      // i

    // [101 13 - 101 23]
    IL_0003: ldc.i4.2     
    IL_0004: stloc.1      // j

    // [102 13 - 102 23]
    IL_0005: ldc.i4.3     
    IL_0006: stloc.2      // k

    // [103 13 - 103 36]
    IL_0007: ldloc.0      // i
    IL_0008: ldloc.1      // j
    IL_0009: add          
    IL_000a: ldloc.2      // k
    IL_000b: add          
    IL_000c: stloc.3      // answer

    // [104 13 - 104 27]
    IL_000d: ldloc.3      // answer
    IL_000e: stloc.s      V_4
    IL_0010: br.s         IL_0012

    // [105 9 - 105 10]
    IL_0012: ldloc.s      V_4
    IL_0014: ret          
	IL_0017: ret
";
            {
#if JS
                TypeDefine.AssemblyDefine.ReadAndRun(AppDomain.CurrentDomain.BaseDirectory + "TestLib.dll", "Test", "ClassRun");
#endif

                //Test.RunArray();
                TypeDefine.AssemblyDefine.ReadAndRun(AppDomain.CurrentDomain.BaseDirectory + "TestLib.dll", "Test",
                                                     "EventTest");

                Console.ReadLine();
                var func = MethodTasks.Build(code).Compile();


                sw.Restart();
                sw.Start();
                for (int i = 0; i < count; i++)
                {
                    func.Run(null);
                }
                sw.Stop();

                p1 = sw.ElapsedMilliseconds;
                Console.WriteLine(sw.ElapsedMilliseconds);
            }

            {
                sw.Restart();
                sw.Start();
                for (int i = 0; i < count; i++)
                {
                    Run1();
                }

                sw.Stop();
                Console.WriteLine(sw.ElapsedMilliseconds);
                p2 = sw.ElapsedMilliseconds;
            }

            Console.WriteLine("P1/P2:" + p1 * 1.0f / p2);
            Console.ReadLine();
        }
Пример #2
0
        static unsafe void Main(string[] args)
        {
            int count = 10000 * 1000;

            var sw = new Stopwatch();


            long p1   = 0;
            long p2   = 0;
            var  code = @"
	IL_0000: ldarg.0
	IL_0001: ldc.i4.2
	IL_0002: bge.s IL_0006

	IL_0004: ldarg.0
	IL_0005: ret

	IL_0006: ldarg.0
	IL_0007: ldc.i4.1
	IL_0008: sub
	IL_0009: call int32 ApolloClr.Program::fib(int32)
	IL_000e: ldarg.0
	IL_000f: ldc.i4.2
	IL_0010: sub
	IL_0011: call int32 ApolloClr.Program::fib(int32)
	IL_0016: add
	IL_0017: ret
";
            {
#if JS
                TypeDefine.AssemblyDefine.ReadAndRun(AppDomain.CurrentDomain.BaseDirectory + "TestLib.dll", "Test", "ClassRun");
#endif

                //Test.RunArray();
                TypeDefine.AssemblyDefine.ReadAndRun(AppDomain.CurrentDomain.BaseDirectory + "TestLib.dll", "Test",
                                                     "ClassRun");

                Console.ReadLine();
                var func = MethodTasks.Build(code).Compile();


                sw.Restart();
                sw.Start();
                for (int i = 0; i < count; i++)
                {
                    func.Run();
                }
                sw.Stop();

                p1 = sw.ElapsedMilliseconds;
                Console.WriteLine(sw.ElapsedMilliseconds);
            }

            {
                sw.Restart();
                sw.Start();
                for (int i = 0; i < count; i++)
                {
                    Run1();
                }

                sw.Stop();
                Console.WriteLine(sw.ElapsedMilliseconds);
                p2 = sw.ElapsedMilliseconds;
            }

            Console.WriteLine("P1/P2:" + p1 * 1.0f / p2);
            Console.ReadLine();
        }