Files

74 lines
2.3 KiB
C#
Raw Permalink Normal View History

2021-10-16 22:34:54 +02:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
2021-09-06 21:43:12 +02:00
using System.Linq;
using BenchmarkDotNet.Attributes;
2021-10-07 21:26:14 +02:00
using BenchmarkDotNet.Configs;
2021-09-06 21:43:12 +02:00
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
using Microsoft.VisualStudio.TestPlatform.TestHost;
using NUnit.Framework;
using QuestPDF.Drawing;
2021-10-16 22:34:54 +02:00
using QuestPDF.Drawing.Proxy;
using QuestPDF.Elements;
2021-09-06 21:43:12 +02:00
using QuestPDF.Infrastructure;
using QuestPDF.ReportSample.Layouts;
namespace QuestPDF.ReportSample
{
2021-11-04 01:02:44 +01:00
[SimpleJob(RunStrategy.Monitoring, launchCount: 0, warmupCount: 1, targetCount: 256)]
2021-09-06 21:43:12 +02:00
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
public class PerformanceTests
{
2021-10-16 22:34:54 +02:00
private PageContext PageContext { get; set; }
private DocumentMetadata Metadata { get; set; }
private Container Content { get; set; }
2021-09-06 21:43:12 +02:00
[Test]
public void Run()
{
2021-11-04 01:02:44 +01:00
ImagePlaceholder.Solid = true;
2021-10-07 21:26:14 +02:00
var configuration = ManualConfig
.Create(DefaultConfig.Instance)
.WithOptions(ConfigOptions.DisableOptimizationsValidator);
BenchmarkRunner.Run<PerformanceTests>(configuration);
2021-09-06 21:43:12 +02:00
}
[IterationSetup]
public void GenerateReportData()
{
2021-11-04 01:02:44 +01:00
ImagePlaceholder.Solid = true;
2021-09-06 21:43:12 +02:00
var model = DataSource.GetReport();
2021-10-16 22:34:54 +02:00
var report = new StandardReport(model);
Metadata = report.GetMetadata();
var documentContainer = new DocumentContainer();
report.Compose(documentContainer);
Content = documentContainer.Compose();
PageContext = new PageContext();
DocumentGenerator.RenderPass(PageContext, new FreeCanvas(), Content, Metadata, null);
var sw = new Stopwatch();
sw.Start();
Content.HandleVisitor(x =>
{
if (x is ICacheable)
x.CreateProxy(y => new CacheProxy(y));
});
sw.Stop();
Console.WriteLine($"Creating cache took: {sw.ElapsedMilliseconds}");
2021-09-06 21:43:12 +02:00
}
[Benchmark]
public void GenerationTest()
{
2021-10-16 22:34:54 +02:00
DocumentGenerator.RenderPass(PageContext, new FreeCanvas(), Content, Metadata, null);
2021-09-06 21:43:12 +02:00
}
}
}