Beispiel #1
0
        public async Task TestRuns(string variation, int modelDepth, int sizeOfTemplate, int inserts, int runs)
        {
            var model        = ConstructModelAndPath(modelDepth);
            var baseTemplate = Enumerable.Range(1, 5)
                               .Aggregate("", (seed, current) => seed += " {{" + model.Item2 + "}}");

            while (baseTemplate.Length <= sizeOfTemplate)
            {
                baseTemplate += model.Item2 + "\r\n";
            }

            MorestachioDocumentInfo template = null;

            //make sure this class is JIT'd before we start timing.
            Parser.ParseWithOptions(new ParserOptions("asdf"));

            var       totalTime = Stopwatch.StartNew();
            var       parseTime = Stopwatch.StartNew();
            Stopwatch renderTime;

            for (var i = 0; i < runs; i++)
            {
                template = Parser.ParseWithOptions(new ParserOptions(baseTemplate, () => Stream.Null));
            }

            parseTime.Stop();

            var tmp = template.CreateAndStringifyAsync(model.Item1);

            renderTime = Stopwatch.StartNew();
            for (var i = 0; i < runs; i++)
            {
                var morestachioDocumentResult = await template.CreateAsync(model.Item1);

                using (var f = morestachioDocumentResult.Stream)
                {
                }
            }

            renderTime.Stop();
            totalTime.Stop();

            var modelPerformanceCounterEntity = new PerformanceCounter.ModelPerformanceCounterEntity(variation)
            {
                TimePerRun        = new TimeSpan(totalTime.ElapsedTicks / runs),
                RunOver           = runs,
                ModelDepth        = modelDepth,
                SubstitutionCount = inserts,
                TemplateSize      = sizeOfTemplate,
                ParseTime         = parseTime.Elapsed,
                RenderTime        = renderTime.Elapsed,
                TotalTime         = totalTime.Elapsed
            };

            PerformanceCounter.PerformanceCounters.Add(modelPerformanceCounterEntity);
            Console.WriteLine(PerformanceCounter.ModelPerformanceCounterEntity.Header(" | "));
            Console.WriteLine(modelPerformanceCounterEntity.PrintAsCsv(" | "));
        }
Beispiel #2
0
        public async Task TestRuns(string variation, int modelDepth, int sizeOfTemplate, int inserts, int runs)
        {
            var model        = ConstructModelAndPath(modelDepth);
            var baseTemplate = Enumerable.Range(1, 5)
                               .Aggregate("", (seed, current) => seed += " {{" + model.Item2 + "}}");

            while (baseTemplate.Length <= sizeOfTemplate)
            {
                baseTemplate += model.Item2 + "\r\n";
            }

            MorestachioDocumentInfo template        = null;
            TokenizerResult         tokenizerResult = null;

            //make sure this class is JIT'd before we start timing.
            (await Parser.ParseWithOptionsAsync(new ParserOptions("asdf"))).Create(new object()).Stream.Dispose();

            var totalTime      = Stopwatch.StartNew();
            var tokenizingTime = Stopwatch.StartNew();

            for (var i = 0; i < runs; i++)
            {
                var options          = new ParserOptions(baseTemplate, () => Stream.Null);
                var tokenzierContext = new TokenzierContext(new List <int>(), options.CultureInfo);
                tokenizerResult = await Tokenizer.Tokenize(options, tokenzierContext);
            }

            tokenizingTime.Stop();

            var parseTime = Stopwatch.StartNew();

            for (var i = 0; i < runs; i++)
            {
                var options = new ParserOptions(baseTemplate, () => Stream.Null);
                template = new MorestachioDocumentInfo(options, Parser.Parse(tokenizerResult, options));
            }

            parseTime.Stop();

            var tmp = await template.CreateAndStringifyAsync(model.Item1);

            var renderTime = Stopwatch.StartNew();

            for (var i = 0; i < runs; i++)
            {
                var morestachioDocumentResult = await template.CreateAsync(model.Item1);

                morestachioDocumentResult.Stream.Dispose();
            }

            renderTime.Stop();
            totalTime.Stop();

            var compileTime = Stopwatch.StartNew();
            CompilationResult compilationResult = null;

            for (var i = 0; i < runs; i++)
            {
                compilationResult = template.Compile();
            }

            compileTime.Stop();

            var compiledRenderTime = Stopwatch.StartNew();

            for (var i = 0; i < runs; i++)
            {
                var morestachioDocumentResult = await compilationResult(model.Item1, CancellationToken.None);

                morestachioDocumentResult.Stream.Dispose();
            }

            compiledRenderTime.Stop();

            var modelPerformanceCounterEntity = new PerformanceCounter.ModelPerformanceCounterEntity(variation)
            {
                TimePerRun = new TimeSpan((tokenizingTime.ElapsedTicks / runs) +
                                          (parseTime.ElapsedTicks / runs) +
                                          (renderTime.ElapsedTicks / runs)),
                RunOver            = runs,
                ModelDepth         = modelDepth,
                SubstitutionCount  = inserts,
                TemplateSize       = sizeOfTemplate,
                TokenizingTime     = tokenizingTime.Elapsed,
                ParseTime          = parseTime.Elapsed,
                RenderTime         = renderTime.Elapsed,
                TotalTime          = totalTime.Elapsed,
                CompilerTime       = compileTime.Elapsed,
                CompiledRenderTime = compiledRenderTime.Elapsed
            };

            PerformanceCounter.PerformanceCounters.Add(modelPerformanceCounterEntity);
            //Console.WriteLine(PerformanceCounter.ModelPerformanceCounterEntity.Header(" | "));
            //Console.WriteLine(modelPerformanceCounterEntity.PrintAsCsv(" | "));
        }