-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added benchmarks and test cases for BitmapByteQRCode
- Loading branch information
Showing
2 changed files
with
101 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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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,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"); | ||
} | ||
|
||
} |