public void TestExpressionCanParseOperators(string query) { var sw = new Stopwatches(); IMorestachioExpression expressions = null; TokenzierContext context = null; for (int i = 0; i < 50000; i++) { sw.Start(); context = TokenzierContext.FromText(query); expressions = ExpressionParser.ParseExpression(query, context); sw.Stop(); } Assert.Warn("Result: " + sw.Elapsed + " average: " + sw.ElapsedAverage); //TestContext.Out.WriteLine(); //Assert.That(expressions, Is.Not.Null, () => context.Errors.GetErrorText()); //Assert.That(context.Errors, Is.Empty, () => context.Errors.GetErrorText()); //var visitor = new ToParsableStringExpressionVisitor(); //expressions.Accept(visitor); //var actual = visitor.StringBuilder.ToString(); //Assert.That(actual, Is.EqualTo(query)); //var template = "{{" + query + "}}"; //var data = new Dictionary<string, object>(); //for (var index = 0; index < args.Length; index++) //{ // var arg = args[index]; // data.Add(((char)('A' + index)).ToString(), arg); //} //var result = await ParserFixture.CreateAndParseWithOptions(template, data, ParserOptionTypes.UseOnDemandCompile, options => //{ // //options.Formatters.AddSingleGlobal<object, object>(f => // //{ // // return f; // //}, "Self"); //}); //Assert.That(result, Is.EqualTo((valExp).ToString())); }
public async Task PerformanceCompiledDebuggerTest() { var _products = new List <object>(500); for (int i = 0; i < 500; i++) { //_products.Add(new Dictionary<string, object>() //{ // {"Name", "Name" + i}, // {"Price", i}, // {"Description", Lorem}, //}); _products.Add(new Product() { Name = "Name" + i, Price = i, Description = Lorem }); } var parsingOptions = new ParserOptions(TextTemplateMorestachio, null, Encoding.UTF8, true); parsingOptions.ProfileExecution = false; var parsed = await Parser.ParseWithOptionsAsync(parsingOptions); var andStringifyAsync = await parsed.CreateAndStringifyAsync(new { Products = _products }); var runs = 200; for (int i = 0; i < runs / 5; i++) { andStringifyAsync = await parsed.CreateAndStringifyAsync(new { Products = _products }); } var compiled = parsed.Compile(); var sw = new Stopwatches(); for (int i = 0; i < runs; i++) { sw.Start(); await compiled(new { Products = _products }, CancellationToken.None); //var f = await parsed.CreateAsync(new //{ // Products = _products //}); sw.Stop(); } var swElapsed = sw.Elapsed; Console.WriteLine("Done in: " + HumanizeTimespan(swElapsed) + " thats " + HumanizeTimespan(sw.ElapsedAverage) + " per run with lower " + HumanizeTimespan(sw.ElapsedMin) + " and high " + HumanizeTimespan(sw.ElapsedMax)); #if NETCOREAPP Console.WriteLine("- Mem: " + Process.GetCurrentProcess().PrivateMemorySize64); #endif //PrintPerformanceGroup(profiler.SelectMany(f => f.)) }