示例#1
0
		internal static Stats MeasurePerformance(Action action, float maximumAllowedUnitTime, int samples = 10, int iterations = 100, string name = null) {
			if (!PerformanceTestUtilities.IsOptimized(typeof(OpenIdRelyingParty).Assembly)) {
				Assert.Inconclusive("Unoptimized code.");
			}

			var timer = new MultiSampleCodeTimer(samples, iterations);
			Stats stats;
			using (new HighPerformance()) {
				stats = timer.Measure(name ?? TestContext.CurrentContext.Test.FullName, action);
			}

			stats.AdjustForScale(PerformanceTestUtilities.Baseline.Median);

			TestUtilities.TestLogger.InfoFormat(
				"Performance counters: median {0}, mean {1}, min {2}, max {3}, stddev {4} ({5}%).",
				stats.Median,
				stats.Mean,
				stats.Minimum,
				stats.Maximum,
				stats.StandardDeviation,
				stats.StandardDeviation / stats.Median * 100);

			Assert.IsTrue(stats.Mean < maximumAllowedUnitTime, "The mean time of {0} exceeded the maximum allowable of {1}.", stats.Mean, maximumAllowedUnitTime);
			TestUtilities.TestLogger.InfoFormat("Within {0}% of the maximum allowed time of {1}.", Math.Round((maximumAllowedUnitTime - stats.Mean) / maximumAllowedUnitTime * 100, 1), maximumAllowedUnitTime);

			return stats;
		}
示例#2
0
文件: TestBase.cs 项目: terry2012/DSV
        internal static Stats MeasurePerformance(Func <Task> action, float maximumAllowedUnitTime, int samples = 10, int iterations = 100, string name = null)
        {
            if (!PerformanceTestUtilities.IsOptimized(typeof(OpenIdRelyingParty).Assembly))
            {
                Assert.Inconclusive("Unoptimized code.");
            }

            var   timer = new MultiSampleCodeTimer(samples, iterations);
            Stats stats;

            using (new HighPerformance()) {
                stats = timer.Measure(name ?? TestContext.CurrentContext.Test.FullName, () => action().Wait());
            }

            stats.AdjustForScale(PerformanceTestUtilities.Baseline.Median);

            TestUtilities.TestLogger.InfoFormat(
                "Performance counters: median {0}, mean {1}, min {2}, max {3}, stddev {4} ({5}%).",
                stats.Median,
                stats.Mean,
                stats.Minimum,
                stats.Maximum,
                stats.StandardDeviation,
                stats.StandardDeviation / stats.Median * 100);

            Assert.IsTrue(stats.Mean < maximumAllowedUnitTime, "The mean time of {0} exceeded the maximum allowable of {1}.", stats.Mean, maximumAllowedUnitTime);
            TestUtilities.TestLogger.InfoFormat("Within {0}% of the maximum allowed time of {1}.", Math.Round((maximumAllowedUnitTime - stats.Mean) / maximumAllowedUnitTime * 100, 1), maximumAllowedUnitTime);

            return(stats);
        }
示例#3
0
        static void Main(string[] args)
        {
            var potylica = new Potylica
            {
                DecVal  = 12.12m,
                Dec2Val = (Decimal2)3.45m,
                Dec3Val = (Decimal3)3.451m,
                Stolec  = new Stolec()
            };

            potylica.Stolec.WewDec = 12.1m;

            TypeConverter converter = TypeDescriptor.GetConverter(potylica.Dec2Val);

            bool canConvert = converter.CanConvertFrom(typeof(Decimal));

            Console.WriteLine("Can convert: " + canConvert);



            TypeRegistry.RegisterType("To", typeof(ToolsS));

            /*
             * Console.WriteLine((string)ExpressionEvaluator.GetValue(null, "'Hello World'"));
             * Console.WriteLine((Decimal)ExpressionEvaluator.GetValue(null, "2m * 3m"));
             *
             *
             * Console.WriteLine((Decimal)ExpressionEvaluator.GetValue(potylica, "2m * Dec2Val"));
             * Console.WriteLine((Decimal)ExpressionEvaluator.GetValue(potylica, "Dec2Val * 2m"));
             * Console.WriteLine((Decimal)ExpressionEvaluator.GetValue(potylica, "Dec2Val * Dec2Val"));
             * Console.WriteLine((Decimal)ExpressionEvaluator.GetValue(potylica, "Dec3Val * Dec2Val"));
             * Console.WriteLine((Decimal)ExpressionEvaluator.GetValue(potylica, "Dec2Val * Dec3Val"));
             * Console.WriteLine((Decimal)ExpressionEvaluator.GetValue(potylica, "-Dec3Val"));
             *
             * Console.WriteLine((Decimal)ExpressionEvaluator.GetValue(potylica, "4 * Dec2Val"));
             *
             * Console.WriteLine((bool)ExpressionEvaluator.GetValue(potylica, "Dec2Val == Dec3Val"));
             *
             * Console.WriteLine((string)ExpressionEvaluator.GetValue(potylica, "(2m * DecVal).ToString()"));
             * Console.WriteLine((Decimal)ExpressionEvaluator.GetValue(potylica, "2m * To.Decimal(Dec2Val)"));
             * Console.WriteLine((string)ExpressionEvaluator.GetValue(potylica, "To.Dec2(6 * DecVal)"));
             * Console.WriteLine((Decimal)ExpressionEvaluator.GetValue(potylica, "Dec2Val = 2m"));
             * Console.WriteLine((Decimal2)ExpressionEvaluator.GetValue(potylica, "Dec2Val = new Core.Types.Decimal2(3m)"));
             *
             * Console.WriteLine((string)ExpressionEvaluator.GetValue(potylica, "Dec2Val.ToFullPrecisionString()"));
             */
            var opAdd = new OpADD();

            opAdd.addChild(new IntLiteralNode("2"));
            opAdd.addChild(new IntLiteralNode("5"));
            var    ctx                 = new object();
            int    rezultat            = 1;
            int    kupa                = 1;
            sbyte  kupaSbyte           = 3;
            long   kupaLong            = 3;
            double kupaDouble          = 3;
            MultiSampleCodeTimer timer = new MultiSampleCodeTimer(8, 1000000);

            opAdd.GetValue(ctx);
            /**/

            var promoContext = new PromoContext();

            // działa zajebiście
            {
                var exp    = Expression.Parse("_Attr.Has('CurrentReceipt.TotalQuantityForArticleIndex0000125837')");
                var result = (bool)exp.GetValue(promoContext);
            }

            {
                var exp    = Expression.Parse("_Attr.Has('CurrentReceipt.TotalQuantityForArticleIndex0000125837') ? 1m : 0m");
                var result = (decimal)exp.GetValue(promoContext);
            }

            {
                var exp = Expression.Parse(
                    "{ _Attr.Has('CurrentReceipt.TotalQuantityForArticleIndex0000125837') ? 1m : 0m, "
                    + "_Attr.Has('CurrentReceipt.TotalQuantityForArticleIndex0000268621') ? 1m : 0m }");
                var result = (System.Collections.IEnumerable)exp.GetValue(promoContext);
            }


            {
                var exp = Expression.Parse(
                    "{ _Attr.Has('CurrentReceipt.TotalQuantityForArticleIndex0000125837') ? 1m : 0m, "
                    + "_Attr.Has('CurrentReceipt.TotalQuantityForArticleIndex0000268621') ? 1m : 0m }.sum() < 2");
                var result = exp.GetValue(promoContext);
            }

            {
                var exp = Expression.Parse(
                    "{ _Attr['CurrentReceipt.TotalValueForArticleIndex0000125837', 0m],"
                    + "_Attr['CurrentReceipt.TotalValueForArticleIndex0000130123', 0m]}.max() "
                    + " == _Attr['CurrentReceipt.TotalValueForArticleIndex0000125837', 0m]");

                var result = exp.GetValue(promoContext);
            }

            {
                var exp    = Expression.Parse("_Attr.SelectMin({'Dupa','Kiszka','Pies'}).Item1");
                var result = exp.GetValue(promoContext);
            }

            {
                var exp    = Expression.Parse("_Attr.SelectMax({'Dupa','Kiszka','Pies'})");
                var result = exp.GetValue(promoContext);
            }

            {
                var exp    = Expression.Parse("5m < 6m ? 'ala'[1] : 'ola'[6]");
                var result = (char)exp.GetValue(null);
            }

            {
                var exp    = Expression.Parse("5m < 6m ? 2 + 3 : 8");
                var result = (int)exp.GetValue(null);
            }

            {
                var exp    = Expression.Parse("2 + 3");
                var result = (int)exp.GetValue(null);
            }

            {
                var exp    = Expression.Parse("2m + 3 + DawajDecimala(4m + 3m) < Stolec.WewDec * DecVal + Stolec.Kiszka");
                var result = (bool)exp.GetValue(potylica);
            }


            {
                var exp    = Expression.Parse("2m + 3 < 3.0 * 4m");
                var result = (bool)exp.GetValue(null);
            }

            {
                var exp    = Expression.Parse("2m + 3 < 3.0 * DecVal");
                var result = (bool)exp.GetValue(new Potylica());
            }
            /**/

            {
                var exp    = Expression.Parse("T(System.Globalization.CultureInfo).InvariantCulture");
                var result = (CultureInfo)exp.GetValue(new Potylica());
                Console.WriteLine("mam kulturkę {0}, {1}", result, result == null ? "null": "jakaś jest");
            }

            {
                var exp    = Expression.Parse("T(System.Globalization.CultureInfo).GetCultureInfo('')");
                var result = (CultureInfo)exp.GetValue(new Potylica());
                Console.WriteLine("mam kulturkę {0}, {1}", result, result == null ? "null" : "jakaś jest");
            }

            {
                var exp    = Expression.Parse("DateTime.Now");
                var result = (DateTime)exp.GetValue(new Potylica());
                Console.WriteLine("czasik {0}", result);
            }

            /*
             * {
             *      var exp = Expression.Parse("'kupa' < 'sraczka2'");
             *      var result = (bool)exp.GetValue(null);
             * }
             */
            timer.Measure("10 x Dodawanie przez OpADD pewnie skompilowane",
                          () =>
            {
                opAdd.GetValue(ctx);
                opAdd.GetValue(ctx);
                opAdd.GetValue(ctx);
                opAdd.GetValue(ctx);
                opAdd.GetValue(ctx);

                opAdd.GetValue(ctx);
                opAdd.GetValue(ctx);
                opAdd.GetValue(ctx);
                opAdd.GetValue(ctx);
                opAdd.GetValue(ctx);
            }
                          );
            {
                var springExp = Expression.Parse("2 + 3");

                timer.Measure("2 + 3 parsed expression",
                              () =>
                {
                    springExp.GetValue(null);
                    springExp.GetValue(null);
                    springExp.GetValue(null);
                    springExp.GetValue(null);
                    springExp.GetValue(null);

                    springExp.GetValue(null);
                    springExp.GetValue(null);
                    springExp.GetValue(null);
                    springExp.GetValue(null);
                    springExp.GetValue(null);
                }
                              );

                if ((int)springExp.GetValue(null) != 5)
                {
                    throw new AbnormalProgramTerminationException("pipa");
                }
            }

            {
                var springExp = (BaseNode)Expression.Parse("2 + 3");

                timer.Measure("2 + 3 parsed expression as GetIntValue",
                              () =>
                {
                    springExp.GetValue <int>(null, null);
                    springExp.GetValue <int>(null, null);
                    springExp.GetValue <int>(null, null);
                    springExp.GetValue <int>(null, null);
                    springExp.GetValue <int>(null, null);

                    springExp.GetValue <int>(null, null);
                    springExp.GetValue <int>(null, null);
                    springExp.GetValue <int>(null, null);
                    springExp.GetValue <int>(null, null);
                    springExp.GetValue <int>(null, null);
                }
                              );

                if ((int)springExp.GetValue(null) != 5)
                {
                    throw new AbnormalProgramTerminationException("pipa");
                }
            }

            {
                var springExp = Expression.Parse("2 + 3 - 4 + 5 + 6");

                timer.Measure("2 + 3 - 4 + 5 + 6 parsed expression",
                              () =>
                {
                    springExp.GetValue(null);
                    springExp.GetValue(null);
                    springExp.GetValue(null);
                    springExp.GetValue(null);
                    springExp.GetValue(null);

                    springExp.GetValue(null);
                    springExp.GetValue(null);
                    springExp.GetValue(null);
                    springExp.GetValue(null);
                    springExp.GetValue(null);
                }
                              );

                if ((int)springExp.GetValue(null) != 12)
                {
                    throw new AbnormalProgramTerminationException("12");
                }
            }

            timer.Measure("10 x DodajIntyNatywnie() natywne",
                          () =>
            {
                DodajIntyNatywnie(rezultat, kupa);
                DodajIntyNatywnie(rezultat, kupa);
                DodajIntyNatywnie(rezultat, kupa);
                DodajIntyNatywnie(rezultat, kupa);
                DodajIntyNatywnie(rezultat, kupa);

                DodajIntyNatywnie(rezultat, kupa);
                DodajIntyNatywnie(rezultat, kupa);
                DodajIntyNatywnie(rezultat, kupa);
                DodajIntyNatywnie(rezultat, kupa);
                DodajIntyNatywnie(rezultat, kupa);
            });

            timer.Measure("10 x DodajIntyNatywnieZwrocObject() boxing tylko res",
                          () =>
            {
                DodajIntyNatywnieZwrocObject(rezultat, kupa);
                DodajIntyNatywnieZwrocObject(rezultat, kupa);
                DodajIntyNatywnieZwrocObject(rezultat, kupa);
                DodajIntyNatywnieZwrocObject(rezultat, kupa);
                DodajIntyNatywnieZwrocObject(rezultat, kupa);

                DodajIntyNatywnieZwrocObject(rezultat, kupa);
                DodajIntyNatywnieZwrocObject(rezultat, kupa);
                DodajIntyNatywnieZwrocObject(rezultat, kupa);
                DodajIntyNatywnieZwrocObject(rezultat, kupa);
                DodajIntyNatywnieZwrocObject(rezultat, kupa);
            });

            timer.Measure("10 x DodajIntyPrzezObjectZwrInt() boxing tylko params.",
                          () =>
            {
                DodajIntyPrzezObjectZwrInt(rezultat, kupa);
                DodajIntyPrzezObjectZwrInt(rezultat, kupa);
                DodajIntyPrzezObjectZwrInt(rezultat, kupa);
                DodajIntyPrzezObjectZwrInt(rezultat, kupa);
                DodajIntyPrzezObjectZwrInt(rezultat, kupa);

                DodajIntyPrzezObjectZwrInt(rezultat, kupa);
                DodajIntyPrzezObjectZwrInt(rezultat, kupa);
                DodajIntyPrzezObjectZwrInt(rezultat, kupa);
                DodajIntyPrzezObjectZwrInt(rezultat, kupa);
                DodajIntyPrzezObjectZwrInt(rezultat, kupa);
            });

            timer.Measure("10 x DodajIntyPrzezObject() czyli wszystko boxing",
                          () =>
            {
                DodajIntyPrzezObject(rezultat, kupa);
                DodajIntyPrzezObject(rezultat, kupa);
                DodajIntyPrzezObject(rezultat, kupa);
                DodajIntyPrzezObject(rezultat, kupa);
                DodajIntyPrzezObject(rezultat, kupa);

                DodajIntyPrzezObject(rezultat, kupa);
                DodajIntyPrzezObject(rezultat, kupa);
                DodajIntyPrzezObject(rezultat, kupa);
                DodajIntyPrzezObject(rezultat, kupa);
                DodajIntyPrzezObject(rezultat, kupa);
            });


            timer.Measure("10 x AddIfPossible()2 czyli boxing i rezult object",
                          () =>
            {
                NumberUtils.AddIfPossible2(kupaSbyte, kupaSbyte);
                NumberUtils.AddIfPossible2(kupaSbyte, kupaSbyte);
                NumberUtils.AddIfPossible2(kupaSbyte, kupaSbyte);
                NumberUtils.AddIfPossible2(kupaSbyte, kupaSbyte);
                NumberUtils.AddIfPossible2(kupaSbyte, kupaSbyte);

                NumberUtils.AddIfPossible2(kupaSbyte, kupaSbyte);
                NumberUtils.AddIfPossible2(kupaSbyte, kupaSbyte);
                NumberUtils.AddIfPossible2(kupaSbyte, kupaSbyte);
                NumberUtils.AddIfPossible2(kupaSbyte, kupaSbyte);
                NumberUtils.AddIfPossible2(kupaSbyte, kupaSbyte);
            });


            timer.Measure("10 x AddIfPossible6() czyli pobranie dwóch GetTypeCode + << 3 single dim",
                          () =>
            {
                NumberUtils.AddIfPossible6(rezultat, kupa);
                NumberUtils.AddIfPossible6(rezultat, kupa);
                NumberUtils.AddIfPossible6(rezultat, kupa);
                NumberUtils.AddIfPossible6(rezultat, kupa);
                NumberUtils.AddIfPossible6(rezultat, kupa);

                NumberUtils.AddIfPossible6(rezultat, kupa);
                NumberUtils.AddIfPossible6(rezultat, kupa);
                NumberUtils.AddIfPossible6(rezultat, kupa);
                NumberUtils.AddIfPossible6(rezultat, kupa);
                NumberUtils.AddIfPossible6(rezultat, kupa);
            });

            timer.Measure("10 x AddIfPossible7() czyli pobranie dwóch GetTypeCode + jagged array",
                          () =>
            {
                NumberUtils.AddIfPossible7(rezultat, kupa);
                NumberUtils.AddIfPossible7(rezultat, kupa);
                NumberUtils.AddIfPossible7(rezultat, kupa);
                NumberUtils.AddIfPossible7(rezultat, kupa);
                NumberUtils.AddIfPossible7(rezultat, kupa);

                NumberUtils.AddIfPossible7(rezultat, kupa);
                NumberUtils.AddIfPossible7(rezultat, kupa);
                NumberUtils.AddIfPossible7(rezultat, kupa);
                NumberUtils.AddIfPossible7(rezultat, kupa);
                NumberUtils.AddIfPossible7(rezultat, kupa);
            });

            Console.ReadKey();
        }