Skip to content

Realistic benchmark #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions PreMailer.Net/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PreMailer.Net\PreMailer.Net.csproj" />
</ItemGroup>

</Project>
226 changes: 226 additions & 0 deletions PreMailer.Net/Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -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<Realistic>();
}
}

[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 = @"
<html xmlns=""http://www.w3.org/1999/xhtml"">
<head>
<meta name=""viewport"" content=""width=device-width, initial-scale=1, maximum-scale=1"">

<meta http-equiv=""Content-Type"" content=""text/html; charset=UTF-8"" />
<title>PreMailer Benchmark</title>

</head>

<body bgcolor=""#123"">

<style>
/* -------------------------------------
GLOBAL
------------------------------------- */
* {
margin:0;
padding:0;
}
* { font-family: Arial, sans-serif; font-size:15px; }

img {
max-width: 100%;
}
.collapse {
margin:0;
padding:0;
}
body {
-webkit-font-smoothing:antialiased;
-webkit-text-size-adjust:none;
width: 100%!important;
height: 100%;
}


/* -------------------------------------
ELEMENTS
------------------------------------- */
a { color: #456;}

/* -------------------------------------
HEADER
------------------------------------- */
table.head-wrap { width: 100%;}
.header .content{
border-left:1px solid black;
border-right:1px solid black;
border-top:1px solid black;
}

/* -------------------------------------
BODY
------------------------------------- */
table.body-wrap { width: 100%;}
.body .content{
border-left:1px solid black;
border-right:1px solid black;
border-bottom:1px solid black;
}

/* -------------------------------------
FOOTER
------------------------------------- */
table.footer-wrap { width: 100%;}


/* -------------------------------------
TYPOGRAPHY
------------------------------------- */
h1,h2,h3,h4,h5,h6 {
font-family: Arial, sans-serif; line-height: 1.1; margin-bottom:15px; color:#000;
}

h1 { font-weight:200; font-size: 28px;}
h2 { font-weight:200; font-size: 20px;}
h3 { font-weight:500; font-size: 16px;}

.collapse { margin:0!important;}

p, ul {
margin-bottom: 10px;
font-weight: normal;
font-size:14px;
line-height:1.6;
}

ul li {
margin-left:5px;
list-style-position: inside;
}


/* ---------------------------------------------------
RESPONSIVENESS
Nuke it from orbit. It's the only way to be sure.
------------------------------------------------------ */

/* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone */
.container {
display:block!important;
max-width:600px!important;
margin:0 auto!important; /* makes it centered */
clear:both!important;
}

/* This should also be a block element, so that it will fill 100% of the .container */
.content {
padding:15px;
max-width:600px;
margin:0 auto;
display:block;
}

/* Make sure tables in the content area are 100% wide */
.content table { width: 100%; }


/* Odds and ends */
.column {
width: 300px;
float:left;
}
.column tr td { padding: 15px; }
.column-wrap {
padding:0!important;
margin:0 auto;
max-width:600px!important;
}
.column table { width:100%;}
.social .column {
width: 280px;
min-width: 279px;
float:left;
}

/* Be sure to place a .clear element after each set of columns, just to be safe */
.clear { display: block; clear: both; }

</style>

<table><tr><td height=""10"">&nbsp;</td></tr></table>
<!-- HEADER -->
<table class=""head-wrap"" cellspacing=""0"">
<tr>
<td></td>
<td class=""header container"">

<div class=""content"">
<table>
<tr>
<td align=""center""><img style=""max-width:200px;"" width=""200"" src=""https://dummy-url.invalid"" alt="""" /></td>
</tr>
</table>
</div>

</td>
<td></td>
</tr>
</table><!-- /HEADER -->


<!-- BODY -->
<table class=""body-wrap"" cellspacing=""0"">
<tr>
<td></td>
<td class=""body container"">

<div class=""content"">
<table>
<tr>
<td>
Hello!<br />
<br />
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.
<br />
<br />
<div>
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.
</div>
<br />
<br />
<br />
<br/><br/>
</td>
</tr>
</table>
</div><!-- /content --></td>
<td></td>
</tr>
</table><!-- /BODY -->


</body>
</html>";
}
10 changes: 8 additions & 2 deletions PreMailer.Net/PreMailer.Net.sln
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down