| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Diagnostics;
- using System.Linq;
- using BenchmarkDotNet.Attributes;
- using BenchmarkDotNet.Configs;
- using BenchmarkDotNet.Engines;
- using BenchmarkDotNet.Running;
- using NUnit.Framework;
- using QuestPDF.Drawing;
- using QuestPDF.Drawing.Proxy;
- using QuestPDF.Elements;
- using QuestPDF.Fluent;
- using QuestPDF.Helpers;
- using QuestPDF.Infrastructure;
- namespace QuestPDF.Examples
- {
- [SimpleJob(RunStrategy.Monitoring, launchCount: 0, warmupCount: 1, targetCount: 16)]
- [MinColumn, MaxColumn, MeanColumn, MedianColumn]
- public class TablePerformanceTest
- {
- private static Random Random { get; } = new Random();
-
- private PageContext PageContext { get; set; }
- private DocumentMetadata Metadata { get; set; }
- private Container Content { get; set; }
- [Test]
- public void Run()
- {
- var configuration = ManualConfig
- .Create(DefaultConfig.Instance)
- .WithOptions(ConfigOptions.DisableOptimizationsValidator);
-
- BenchmarkRunner.Run<TablePerformanceTest>(configuration);
- }
-
- [IterationSetup]
- [SetUp]
- public void GenerateReportData()
- {
- Metadata = new DocumentMetadata()
- {
- DocumentLayoutExceptionThreshold = 1000
- };
-
- var documentContainer = new DocumentContainer();
- documentContainer.Page(page =>
- {
- page.Size(PageSizes.A3);
- GeneratePerformanceStructure(page.Content(), 10_000);
- });
-
- Content = documentContainer.Compose();
- PageContext = new PageContext();
- DocumentGenerator.RenderPass(PageContext, new FreeCanvas(), Content, Metadata, null);
- Content.HandleVisitor(x =>
- {
- if (x is ICacheable)
- x.CreateProxy(y => new CacheProxy(y));
- });
- }
- [Benchmark]
- [Test]
- public void GenerationTest()
- {
- DocumentGenerator.RenderPass(PageContext, new FreeCanvas(), Content, Metadata, null);
- }
-
- void GeneratePerformanceStructure(IContainer container, int itemsCount)
- {
- container
- .Padding(25)
- .Table(table =>
- {
- table.ColumnsDefinition(columns =>
- {
- foreach (var size in Enumerable.Range(0, 10))
- columns.ConstantColumn(100);
- });
- foreach (var i in Enumerable.Range(1, itemsCount))
- {
- table
- .Cell()
- .RowSpan((uint)Random.Next(1, 5))
- .ColumnSpan((uint)Random.Next(1, 5))
- .Element(CreateBox(i.ToString()));
- }
- });
- }
-
- private Action<IContainer> CreateBox(string label)
- {
- return container =>
- {
- var height = Random.Next(2, 6) * 20;
-
- container
- .Border(2)
- .Background(Placeholders.BackgroundColor())
- .AlignCenter()
- .AlignMiddle()
- .Height(height)
- .Text($"{label}: {height}px");
- };
- }
- }
- }
|