|
| 1 | +// Copyright (c) Alexandre Mutel. All rights reserved. |
| 2 | +// This file is licensed under the BSD-Clause 2 license. |
| 3 | +// See the license.txt file in the project root for more information. |
| 4 | + |
| 5 | +using BenchmarkDotNet.Attributes; |
| 6 | +using BenchmarkDotNet.Diagnosers; |
| 7 | +using Markdig; |
| 8 | + |
| 9 | +namespace Testamina.Markdig.Benchmarks.PipeTable; |
| 10 | + |
| 11 | +/// <summary> |
| 12 | +/// Benchmark for pipe table parsing performance, especially for large tables. |
| 13 | +/// Tests the performance of PipeTableParser with varying table sizes. |
| 14 | +/// </summary> |
| 15 | +[MemoryDiagnoser] |
| 16 | +[GcServer(true)] // Use server GC to get more comprehensive GC stats |
| 17 | +public class PipeTableBenchmark |
| 18 | +{ |
| 19 | + private string _100Rows = null!; |
| 20 | + private string _500Rows = null!; |
| 21 | + private string _1000Rows = null!; |
| 22 | + private string _1500Rows = null!; |
| 23 | + private string _5000Rows = null!; |
| 24 | + private string _10000Rows = null!; |
| 25 | + private MarkdownPipeline _pipeline = null!; |
| 26 | + |
| 27 | + [GlobalSetup] |
| 28 | + public void Setup() |
| 29 | + { |
| 30 | + // Pipeline with pipe tables enabled (part of advanced extensions) |
| 31 | + _pipeline = new MarkdownPipelineBuilder() |
| 32 | + .UseAdvancedExtensions() |
| 33 | + .Build(); |
| 34 | + |
| 35 | + // Generate tables of various sizes |
| 36 | + // Note: Before optimization, 5000+ rows hit depth limit due to nested tree structure. |
| 37 | + // After optimization, these should work. |
| 38 | + _100Rows = PipeTableGenerator.Generate(rows: 100, columns: 5); |
| 39 | + _500Rows = PipeTableGenerator.Generate(rows: 500, columns: 5); |
| 40 | + _1000Rows = PipeTableGenerator.Generate(rows: 1000, columns: 5); |
| 41 | + _1500Rows = PipeTableGenerator.Generate(rows: 1500, columns: 5); |
| 42 | + _5000Rows = PipeTableGenerator.Generate(rows: 5000, columns: 5); |
| 43 | + _10000Rows = PipeTableGenerator.Generate(rows: 10000, columns: 5); |
| 44 | + } |
| 45 | + |
| 46 | + [Benchmark(Description = "PipeTable 100 rows x 5 cols")] |
| 47 | + public string Parse100Rows() |
| 48 | + { |
| 49 | + return Markdown.ToHtml(_100Rows, _pipeline); |
| 50 | + } |
| 51 | + |
| 52 | + [Benchmark(Description = "PipeTable 500 rows x 5 cols")] |
| 53 | + public string Parse500Rows() |
| 54 | + { |
| 55 | + return Markdown.ToHtml(_500Rows, _pipeline); |
| 56 | + } |
| 57 | + |
| 58 | + [Benchmark(Description = "PipeTable 1000 rows x 5 cols")] |
| 59 | + public string Parse1000Rows() |
| 60 | + { |
| 61 | + return Markdown.ToHtml(_1000Rows, _pipeline); |
| 62 | + } |
| 63 | + |
| 64 | + [Benchmark(Description = "PipeTable 1500 rows x 5 cols")] |
| 65 | + public string Parse1500Rows() |
| 66 | + { |
| 67 | + return Markdown.ToHtml(_1500Rows, _pipeline); |
| 68 | + } |
| 69 | + |
| 70 | + [Benchmark(Description = "PipeTable 5000 rows x 5 cols")] |
| 71 | + public string Parse5000Rows() |
| 72 | + { |
| 73 | + return Markdown.ToHtml(_5000Rows, _pipeline); |
| 74 | + } |
| 75 | + |
| 76 | + [Benchmark(Description = "PipeTable 10000 rows x 5 cols")] |
| 77 | + public string Parse10000Rows() |
| 78 | + { |
| 79 | + return Markdown.ToHtml(_10000Rows, _pipeline); |
| 80 | + } |
| 81 | +} |
0 commit comments