Ejemplo n.º 1
0
        static void testMapping()
        {
            var pattern = "var f; function k(){var t=0; while(false) t=t;}    function a(){ var t=0; while(t<1) ++t; return t>3; } /*a();*/ var c=b.Name; var d=b.Age; b.Age=15; /*for(var i=0;i<100;++i){ d=b.Age;b.Age=i; b.Name=\"cat\"; c=b.Say();b.Add(); f=a(); k();}*/";

            Tokenizer tg     = new Tokenizer();
            var       watch  = new Stopwatch();
            var       reader = new SequenceReader <Token>(tg.Tokenize(pattern));

            var block = new TopBlock();
            var p     = new Animal {
                Name = "dog", Age = 10
            };

            block.Declare("b", new JMappingObject(p));
            var builder = new TopBlockBuilder(reader, block);

            builder.Build();

            watch.Start();
            builder.Block.Excute(null);
            Console.WriteLine(watch.ElapsedMilliseconds);
            Console.WriteLine("c is " + block.GetVariable("c"));
            Console.WriteLine("d is " + block.GetVariable("d"));
            Console.WriteLine("f is " + block.GetVariable("f"));
            Console.WriteLine(p.Age);
            Console.WriteLine(p.Name);
            Console.Read();
        }
Ejemplo n.º 2
0
        static void tsetExcute()
        {
            var pattern = " var d=\"hello\"+\" world!\"; var b=d==\"hello world!\";var f=d+\" just for test! \";  var a=15; function add(b,c){ var t=0; for(var i=b;i<c;++i) t=t+i*5;   return t;}  var c= add(1,100000); ";


            Tokenizer tg    = new Tokenizer();
            var       watch = new Stopwatch();



            for (int i = 0; i < 100000; i++)
            {
                var reader = new SequenceReader <Token>(tg.Tokenize(pattern));

                var block = new TopBlock();

                var builder = new TopBlockBuilder(reader, block);
                builder.Build();

                watch.Start();
                builder.Block.Excute(null);

                Console.WriteLine(watch.ElapsedMilliseconds);
                Console.WriteLine("a is " + block.GetVariable("a"));
                Console.WriteLine("c is " + block.GetVariable("c").ToString());
                Console.WriteLine("b is " + block.GetVariable("b").ToString());
                Console.WriteLine("d is " + block.GetVariable("d"));
                Console.WriteLine("f is " + block.GetVariable("f"));
                Console.Read();
            }
            Console.WriteLine($"spend:{watch.ElapsedMilliseconds} ");


            var watch2 = new Stopwatch();

            watch2.Start();
            var a = 7;
            var b = 9;

            for (int i = 0; i < 10000; i++)
            {
                var c = (a + b * b - a) - a * 7 + a - b + b + b * a;
            }

            Console.WriteLine(watch2.ElapsedMilliseconds);
        }