From c3903b361dc7344be60ff4df5b83d43e44f839c4 Mon Sep 17 00:00:00 2001 From: Patrik Westerlund Date: Sat, 31 Dec 2022 09:24:30 +0100 Subject: [PATCH] Realistic benchmark --- PreMailer.Net/Benchmarks/Benchmarks.csproj | 17 ++ PreMailer.Net/Benchmarks/Program.cs | 226 +++++++++++++++++++++ PreMailer.Net/PreMailer.Net.sln | 10 +- 3 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 PreMailer.Net/Benchmarks/Benchmarks.csproj create mode 100644 PreMailer.Net/Benchmarks/Program.cs diff --git a/PreMailer.Net/Benchmarks/Benchmarks.csproj b/PreMailer.Net/Benchmarks/Benchmarks.csproj new file mode 100644 index 00000000..98752691 --- /dev/null +++ b/PreMailer.Net/Benchmarks/Benchmarks.csproj @@ -0,0 +1,17 @@ + + + + Exe + netcoreapp3.1 + enable + + + + + + + + + + + diff --git a/PreMailer.Net/Benchmarks/Program.cs b/PreMailer.Net/Benchmarks/Program.cs new file mode 100644 index 00000000..5ea21784 --- /dev/null +++ b/PreMailer.Net/Benchmarks/Program.cs @@ -0,0 +1,226 @@ +using AngleSharp; +using AngleSharp.Html.Parser; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Running; + +public static class Program +{ + public static void Main() + { + BenchmarkRunner.Run(); + } +} + +[SimpleJob(invocationCount: 100, iterationCount: 100)] +[MemoryDiagnoser] +public class Realistic +{ + [Benchmark] + public void AngleSharpBaseline() + { + new HtmlParser().ParseDocument(RawHtml).ToHtml(); + } + + [Benchmark] + public void MoveCssInline() + { + PreMailer.Net.PreMailer.MoveCssInline(RawHtml); + } + + private static readonly string RawHtml = @" + + + + + +PreMailer Benchmark + + + + + + + +
 
+ + + + + + + +
+ +
+ + + + +
+
+ +
+ + + + + + + + + +
+ +
+ + + + +
+Hello!
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. +
+
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. +
+
+
+
+

+
+
+ + + +"; +} \ No newline at end of file diff --git a/PreMailer.Net/PreMailer.Net.sln b/PreMailer.Net/PreMailer.Net.sln index b8b7e326..49d428fa 100644 --- a/PreMailer.Net/PreMailer.Net.sln +++ b/PreMailer.Net/PreMailer.Net.sln @@ -1,12 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27703.2035 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33205.214 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PreMailer.Net", "PreMailer.Net\PreMailer.Net.csproj", "{7B4A85FA-FA98-40FD-83B7-5E84C8853736}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PreMailer.Net.Tests", "PreMailer.Net.Tests\PreMailer.Net.Tests.csproj", "{F5A0FED0-4A6C-49AA-B49E-C47A034D8098}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "Benchmarks\Benchmarks.csproj", "{FAF28642-7D4C-48E3-BAA4-AAD28E5A6847}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {F5A0FED0-4A6C-49AA-B49E-C47A034D8098}.Debug|Any CPU.Build.0 = Debug|Any CPU {F5A0FED0-4A6C-49AA-B49E-C47A034D8098}.Release|Any CPU.ActiveCfg = Release|Any CPU {F5A0FED0-4A6C-49AA-B49E-C47A034D8098}.Release|Any CPU.Build.0 = Release|Any CPU + {FAF28642-7D4C-48E3-BAA4-AAD28E5A6847}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FAF28642-7D4C-48E3-BAA4-AAD28E5A6847}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FAF28642-7D4C-48E3-BAA4-AAD28E5A6847}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FAF28642-7D4C-48E3-BAA4-AAD28E5A6847}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE