Пример #1
0
        public void NestedComparisonTest()
        {
            var wrapperA = new FloatClassWrapper <Vector2> .FloatWrapperA <Tuple <string, string>, float>(2);

            FloatWrapperB wrapperB = new FloatWrapperB(2);
            Dictionary <string, object> objDictionary = new Dictionary <string, object>();

            objDictionary.Add("floatWrapper_a", wrapperA);
            objDictionary.Add("floatWrapper_b", wrapperB);
            var schema = FloatComparisonNestedSchemata();

            var condGate = new ConditionFactory(objDictionary).Build(schema);

            Assert.True(condGate.Met());
            schema.conditionType = ConditionType.And;
            condGate             = new ConditionFactory(objDictionary).Build(schema);
            Assert.False(condGate.Met());
            wrapperB.f = 1;
            Assert.True(condGate.Met());

            Stopwatch watch = new Stopwatch();

            condGate.Met(); // clearing for cache and JiT
            watch.Start();
            for (int i = 0; i < 1000000; i++)
            {
                condGate.Met();
            }
            watch.Stop();
            Console.WriteLine("Elapsed milliseconds for dynamically compiled method: " + watch.ElapsedMilliseconds);
            ICondition hardCodedConditionGate = new ConditionsGate(ConditionType.And, new ConditionAtom(() => wrapperA.f >= 2, false), new ConditionAtom(() => wrapperB.f < 2, false));

            watch.Reset();
            hardCodedConditionGate.Met(); // clearing cache and JiT
            watch.Start();
            for (int i = 0; i < 1000000; i++)
            {
                hardCodedConditionGate.Met();
            }
            watch.Stop();
            Console.WriteLine("Elapsed milliseconds for hard-coded delegate: " + watch.ElapsedMilliseconds);

            dynamic    dyn_wrapperA         = wrapperA;
            dynamic    dyn_wrapperB         = wrapperB;
            ICondition dynamicConditionGate = new ConditionsGate(ConditionType.And, new ConditionAtom(() => dyn_wrapperA.f >= 2, false), new ConditionAtom(() => dyn_wrapperB.f < 2, false));

            watch.Reset();
            dynamicConditionGate.Met(); // clearing cache and JiT
            watch.Start();
            for (int i = 0; i < 1000000; i++)
            {
                dynamicConditionGate.Met();
            }
            watch.Stop();
            Console.WriteLine("Elapsed milliseconds for dynamically-typed, hard-coded delegate: " + watch.ElapsedMilliseconds);
        }
Пример #2
0
        private async Task <object> TaskRunner()
        {
            var wrapperA = new FloatClassWrapper <Vector2> .FloatWrapperA <Tuple <string, string>, float>(2);

            var wrapperB = new FloatWrapperB(2);
            var schema   = FloatComparisonNestedSchemata();
            var schema_2 = FloatComparisonNestedSchemata();
            var schema_3 = FloatComparisonNestedSchemata();
            Dictionary <string, object> objDictionary = new Dictionary <string, object>();

            objDictionary.Add("floatWrapper_a", wrapperA);
            objDictionary.Add("floatWrapper_b", wrapperB);

            var a = AsyncTest(objDictionary, schema);
            var b = AsyncTest(objDictionary, schema_2);
            var c = Task.Run(async() => new ConditionFactory(objDictionary).Build(schema_3));

            return(await Task.WhenAll(a, b, c));
        }