Skip to content

Commit

Permalink
Added benchmarks and test cases for BitmapByteQRCode
Browse files Browse the repository at this point in the history
  • Loading branch information
codebude committed Jun 22, 2024
1 parent fc48785 commit b46dac6
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
51 changes: 51 additions & 0 deletions QRCoderBenchmarks/BitmapByteQRCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Collections.ObjectModel;
using BenchmarkDotNet.Attributes;
using QRCoder;

namespace QRCoderBenchmarks;

[MemoryDiagnoser]
public class BitmapByteQRCodeBenchmark
{
private readonly Dictionary<string, QRCodeData> _samples;

public BitmapByteQRCodeBenchmark()
{
var eccLvl = QRCoder.QRCodeGenerator.ECCLevel.L;
_samples = new Dictionary<string, QRCodeData>()
{
{ "small", QRCoder.QRCodeGenerator.GenerateQrCode("ABCD", eccLvl) },
{ "medium", QRCoder.QRCodeGenerator.GenerateQrCode("https://github.com/codebude/QRCoder/blob/f89aa90081f369983a9ba114e49cc6ebf0b2a7b1/QRCoder/Framework4.0Methods/Stream4Methods.cs", eccLvl) },
{ "big", QRCoder.QRCodeGenerator.GenerateQrCode( new string('a', 2600), eccLvl) }
};
}


[Benchmark]
public void RenderBitmapByteQRCodeSmall()
{
var qrCode = new BitmapByteQRCode(_samples["small"]);
_ = qrCode.GetGraphic(10);
}

[Benchmark]
public void RenderBitmapByteQRCodeMedium()
{
var qrCode = new BitmapByteQRCode(_samples["medium"]);
_ = qrCode.GetGraphic(10);
}

[Benchmark]
public void RenderBitmapByteQRCodeBig()
{
var qrCode = new BitmapByteQRCode(_samples["big"]);
_ = qrCode.GetGraphic(10);
}

[Benchmark]
public void RenderBitmapByteQRCodeHuge()
{
var qrCode = new BitmapByteQRCode(_samples["big"]);
_ = qrCode.GetGraphic(50);
}
}
50 changes: 50 additions & 0 deletions QRCoderTests/BitmapByteQRCodeRendererTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using QRCoder;
using QRCoderTests.Helpers;
using QRCoderTests.Helpers.XUnitExtenstions;
using Shouldly;
using Xunit;


namespace QRCoderTests;


public class BitmapByteQRCodeRendererTests
{
[Fact]
[Category("QRRenderer/BitmapByteQRCode")]
public void can_render_bitmapbyte_qrcode()
{
var gen = new QRCodeGenerator();
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H);
var bmp = new BitmapByteQRCode(data).GetGraphic(10);

var result = HelperFunctions.ByteArrayToHash(bmp);
result.ShouldBe("2d262d074f5c436ad93025150392dd38");
}


[Fact]
[Category("QRRenderer/BitmapByteQRCode")]
public void can_render_bitmapbyte_qrcode_color_bytearray()
{
var gen = new QRCodeGenerator();
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H);
var bmp = new BitmapByteQRCode(data).GetGraphic(10, new byte[] { 30, 30, 30 }, new byte[] { 255, 0, 0 });

var result = HelperFunctions.ByteArrayToHash(bmp);
result.ShouldBe("1184507c7eb98f9ca76afd04313c41cb");
}

[Fact]
[Category("QRRenderer/BitmapByteQRCode")]
public void can_render_bitmapbyte_qrcode_drawing_color()
{
var gen = new QRCodeGenerator();
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H);
var bmp = new BitmapByteQRCode(data).GetGraphic(10, "#e3e3e3", "#ffffff");

var result = HelperFunctions.ByteArrayToHash(bmp);
result.ShouldBe("40cd208fc46aa726d6e98a2028ffd2b7");
}

}

0 comments on commit b46dac6

Please sign in to comment.