예제 #1
0
        public void PerformanceOfMethodEvaluationOnDifferentContextTypes()
        {
            MethodNode mn = new MethodNode();
            mn.Text = "ToString";

            TypeNode nln = new TypeNode();
            nln.Text = "System.Globalization.CultureInfo";

            PropertyOrFieldNode pn = new PropertyOrFieldNode();
            pn.Text = "InvariantCulture";


            Expression exp = new Expression();
            exp.addChild(nln);
            exp.addChild(pn);

            StringLiteralNode sln = new StringLiteralNode();
            sln.Text = "dummy";

            mn.addChild(sln);
            mn.addChild(exp);

            IExpression mnExp = mn;
            Assert.AreEqual("dummy", mnExp.GetValue(0m, null));

            int runs = 10000000;

            StopWatch watch = new StopWatch();
            using (watch.Start("Duration: {0}"))
            {
                for (int i = 0; i < runs; i++)
                {
                    mnExp.GetValue(0m, null);
                }
            }
        }