-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
14,546 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,3 +162,5 @@ coverity.zip | |
*.lock.json | ||
*.nuget.props | ||
*.nuget.targets | ||
|
||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
test/HtmlSanitizer.Benchmark/HtmlSanitizer.Benchmark.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<LangVersion>9.0</LangVersion> | ||
<SonarQubeExclude>true</SonarQubeExclude> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\HtmlSanitizer\HtmlSanitizer.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="*.html" CopyToOutputDirectory="PreserveNewest" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.IO; | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Ganss.XSS.Benchmark | ||
{ | ||
[MemoryDiagnoser] | ||
public class HtmlSanitizerBenchmark | ||
{ | ||
private HtmlSanitizer sanitizer; | ||
private string googleFileContent; | ||
private string largeFileContent; | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
googleFileContent = File.ReadAllText("google.html"); | ||
largeFileContent = File.ReadAllText("ecmascript.html"); | ||
sanitizer = new HtmlSanitizer(); | ||
} | ||
|
||
/// <summary> | ||
/// Small content produced by for example Orchard, nothing to sanitize. | ||
/// </summary> | ||
[Benchmark] | ||
public void SanitizeSmall() | ||
{ | ||
sanitizer.Sanitize("<p>Never in all their history have men been able truly to conceive of the world as one: a single sphere, a globe, having the qualities of a globe, a round earth in which all the directions eventually meet, in which there is no center because every point, or none, is center — an equal earth which all men occupy as equals. The airman's earth, if free men make it, will be truly round: a globe in practice, not in theory.</p>\n<p>Science cuts two ways, of course; its products can be used for both good and evil. But there's no turning back from science. The early warnings about technological dangers also come from science.</p>\n<p>What was most significant about the lunar voyage was not that man set foot on the Moon but that they set eye on the earth.</p>\n<p>A Chinese tale tells of some men sent to harm a young girl who, upon seeing her beauty, become her protectors rather than her violators. That's how I felt seeing the Earth for the first time. I could not help but love and cherish her.</p>\n<p>For those who have seen the Earth from space, and for the hundreds and perhaps thousands more who will, the experience most certainly changes your perspective. The things that we share in our world are far more valuable than those which divide us.</p>\n"); | ||
} | ||
|
||
/// <summary> | ||
/// Google is script-heavy. | ||
/// </summary> | ||
[Benchmark] | ||
public void SanitizeGoogle() | ||
{ | ||
sanitizer.Sanitize(googleFileContent); | ||
} | ||
|
||
/// <summary> | ||
/// Partial ECMAScript is DOM-heavy. | ||
/// </summary> | ||
[Benchmark] | ||
public void SanitizeLarge() | ||
{ | ||
sanitizer.Sanitize(largeFileContent); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace Ganss.XSS.Benchmark | ||
{ | ||
public static class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
BenchmarkSwitcher.FromAssembly(typeof(HtmlSanitizerBenchmark).Assembly).Run(args); | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.