Skip to content
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

Add benchmarking #508

Merged
merged 2 commits into from
Apr 29, 2024
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
4 changes: 3 additions & 1 deletion .github/workflows/wf-build-release-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
2.0.x
5.0.x
6.0.x
8.0.x

- name: Restore NuGet Packages
run: dotnet restore
Expand Down Expand Up @@ -51,7 +52,8 @@ jobs:
1.0.x
2.0.x
5.0.x
6.0.x
6.0.x
8.0.x

- name: Run test .NET 3.5
working-directory: QRCoderTests
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/wf-build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
2.0.x
5.0.x
6.0.x
8.0.x

- name: Restore NuGet Packages
run: dotnet restore
Expand Down Expand Up @@ -52,7 +53,8 @@ jobs:
1.0.x
2.0.x
5.0.x
6.0.x
6.0.x
8.0.x

- name: Run test .NET 3.5
working-directory: QRCoderTests
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/wf-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
2.0.x
5.0.x
6.0.x
8.0.x

- name: Restore NuGet Packages
run: dotnet restore
Expand Down Expand Up @@ -51,7 +52,8 @@ jobs:
1.0.x
2.0.x
5.0.x
6.0.x
6.0.x
8.0.x

- name: Run test .NET 3.5
working-directory: QRCoderTests
Expand Down
18 changes: 18 additions & 0 deletions QRCoder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QRCoder.Xaml", "QRCoder.Xam
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QRCoderApiTests", "QRCoderApiTests\QRCoderApiTests.csproj", "{5FACE5F6-53C9-4B89-91D4-162677893574}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QRCoderBenchmarks", "QRCoderBenchmarks\QRCoderBenchmarks.csproj", "{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -137,6 +139,22 @@ Global
{5FACE5F6-53C9-4B89-91D4-162677893574}.Release|x64.Build.0 = Release|Any CPU
{5FACE5F6-53C9-4B89-91D4-162677893574}.Release|x86.ActiveCfg = Release|Any CPU
{5FACE5F6-53C9-4B89-91D4-162677893574}.Release|x86.Build.0 = Release|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Debug|ARM.ActiveCfg = Debug|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Debug|ARM.Build.0 = Debug|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Debug|x64.ActiveCfg = Debug|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Debug|x64.Build.0 = Debug|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Debug|x86.ActiveCfg = Debug|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Debug|x86.Build.0 = Debug|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Release|Any CPU.Build.0 = Release|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Release|ARM.ActiveCfg = Release|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Release|ARM.Build.0 = Release|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Release|x64.ActiveCfg = Release|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Release|x64.Build.0 = Release|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Release|x86.ActiveCfg = Release|Any CPU
{C33AB74A-2AB3-4BEA-A67F-EAB578E74E25}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions QRCoderBenchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using BenchmarkDotNet.Running;

BenchmarkRunner.Run(typeof(Program).Assembly);
23 changes: 23 additions & 0 deletions QRCoderBenchmarks/QRCodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using BenchmarkDotNet.Attributes;

namespace QRCoderBenchmarks;

[MemoryDiagnoser]
public class QRCodeGenerator
{
[Benchmark]
public void CreateQRCode()
{
var payload = new QRCoder.PayloadGenerator.Url("HTTP://WWW.GOOGLE.COM/");
QRCoder.QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
_ = qrGenerator.CreateQrCode(payload, QRCoder.QRCodeGenerator.ECCLevel.L);
}

[Benchmark]
public void CreateQRCodeLong()
{
var payload = new QRCoder.PayloadGenerator.Url("https://github.com/codebude/QRCoder/blob/f89aa90081f369983a9ba114e49cc6ebf0b2a7b1/QRCoder/Framework4.0Methods/Stream4Methods.cs");
QRCoder.QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
_ = qrGenerator.CreateQrCode(payload, QRCoder.QRCodeGenerator.ECCLevel.H);
}
}
18 changes: 18 additions & 0 deletions QRCoderBenchmarks/QRCoderBenchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<ItemGroup>
<ProjectReference Include="..\QRCoder\QRCoder.csproj" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions QRCoderTests/QRGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ public void can_encode_alphanumeric()
result.ShouldBe("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111010111011111110000000010000010001100100000100000000101110101101001011101000000001011101011001010111010000000010111010100100101110100000000100000100111101000001000000001111111010101011111110000000000000000000110000000000000000111100101111110011101000000000111100010011110001110000000000100010100100000001000000000011110011111001110011000000001111101110101001000000000000000000000111100100100100000000111111100001100100110000000001000001000100001111110000000010111010010011111010100000000101110101111001011110000000001011101010101011000000000000010000010111001000010000000000111111101010010010010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
}

[Fact]
[Category("QRGenerator/TextEncoding")]
public void can_encode_byte_long()
{
var gen = new QRCodeGenerator();
var qrData = gen.CreateQrCode("https://github.com/codebude/QRCoder/blob/f89aa90081f369983a9ba114e49cc6ebf0b2a7b1/QRCoder/Framework4.0Methods/Stream4Methods.cs", QRCodeGenerator.ECCLevel.H);
var result = string.Join("", qrData.ModuleMatrix.Select(x => x.ToBitString()).ToArray());
result.ShouldBe("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111110111011110110000101001110011101111011110001011011111110000000010000010111110111110001010010001100010100000011000011010000010000000010111010110010100110110000100110001010110100101010111010111010000000010111010000110010111011000101111110011010101000100101010111010000000010111010011010111000011000101111100001101111110001110010111010000000010000010110101101010101100011000100100100001011101100010000010000000011111110101010101010101010101010101010101010101010101011111110000000000000000111011011010010111001000100010111011010101000000000000000000000111010111110001111111100111111110110000111011110011111001110000000011111101111010101011111100011110101010001011000111000110100000000000000101111000110111101010010011011000010000110010110101000000110000000000000001111100010111100110100010100011010111100000001000100010000000000101010011011100110011111101000111110001100011111011011011110000000010010001110011110000101111001100100011001111110010010011010100000000001010011010001011011011010111011001110110000001001100101011110000000010110000111100111100010110011101110000001101111001000010110010000000010101010100011010111011110111010010100010100000110111111011010000000000110101111110101110100001101100010101110110010111000011010000000000001011111111001010110101000111001001011011000101011111101010110000000000010000000110100110010011100110100000100110111101001011110000000000010101110011111100011001000110101101111001011000011001001001100000000000100000101111001101001100001000010110010111000001000010010100000000010000011000010110111001110111011010010101000111011110100111110000000001100000100110001100100010101111011011100010110101000010000010000000000001111101011110111110100010100101010101111000010000000011110000000011010100010000111011000110000110001011000111110011010011100100000000010010011011110011110011001101110011001110001111110000000011010000000011101000110001100001110010010001011000000010101101110010110100000000010111111101100100010001000111111100111011101000010101111101000000000011001000110101111011001011001000101101011111100001101000100000000000010001010100000111101011101111010101010000000011110011010110110000000010111000100001011000010010011000100000100110101000011000100100000000000001111101111110100000010101111111100001001001110001111111100000000010111001011011001100001101010001000100111111100101011011000000000000000000011111101001100110000110100010001111001111101100111010110000000010101101101010110010011111101010000100100010000110001011010000000000010100011111001110010000010000111111110110001110111111011111010000000000001000000111110111001100111011011010100110100111011110010000000000000110111001011011100010111100000000010010011111010100110111110000000001110000110101101001100001001000111010011100110001111001100110000000001100011100110101100100101001010001100110101000111111101111000000000011101100100001000100011101010100111110101110010101001001010100000000011111110000111010111100001011011101000110100100101000101001010000000010111101100010010110000011101011011101101101101100001011000110000000010101111001111111101011010100000001000100101001010110110101000000000000011101100001001011001110010110111100101110010100000011001100000000010001111010011100000100100110111011011010111011010111110001110000000010000001111101010111111110001110110001011111101110000100000110000000000100010110000000101000111001011000011100011001011111011111110000000010110101101100011101011100001111101011111111000110010000011000000000000111111100010001000110100000001101111110101011011110011010110000000011101000111010011011110100001010110011111101010001001000000010000000011110011110100001110111110011111101110100001001111011111101110000000000000000100110000001011111101000100101001101100110001000110100000000011111110011101111000110110011010110001110011111101111010111110000000010000010010101100101110011001000111101111010111001011000100110000000010111010100001010110001101111111101101000111010111111111101000000000010111010101001111101101011110000100011100011110011011111101010000000010111010100101010001000010100001001101000100001110100010001010000000010000010001010111111111001100110111100101011111000010110000010000000011111110001011000110010001101010000101110110000110101000011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
}

[Fact]
[Category("QRGenerator/TextEncoding")]
public void can_encode_byte()
Expand Down