-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBenchmarks.QrCodeBenchmarks.cs
108 lines (94 loc) · 6.32 KB
/
Benchmarks.QrCodeBenchmarks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using BenchmarkDotNet.Attributes;
using Quarer;
public partial class Benchmarks
{
[ParamsSource(nameof(ArgumentsSource))]
public VersionArgument Version { get; set; } = null!;
private const string Digits = "0123456789";
public class VersionArgument(int version, string data)
{
public int Version { get; } = version;
public string Data { get; } = data;
public override string ToString() => $"Version {Version}";
}
public static IEnumerable<VersionArgument> ArgumentsSource()
{
var numericM = ModeErrorLevelVersionCapacityLookup[0][1];
for (var i = 0; i < 40; i++)
{
yield return new(i + 1, new string(Random.Shared.GetItems(Digits.AsSpan(), numericM[i])));
}
}
public SkiaSharp.QrCode.QRCodeGenerator SkiaGenerator = null!;
public QrCodeEncodingOptions QuarerOptions = null!;
[GlobalSetup]
public void Setup()
{
SkiaGenerator = new SkiaSharp.QrCode.QRCodeGenerator();
QuarerOptions = new QrCodeEncodingOptions { ErrorCorrectionLevel = ErrorCorrectionLevel.M };
}
[Benchmark(Description = "Quarer")]
public QrCode Quarer() => QrCode.Create(Version.Data, QuarerOptions);
[Benchmark(Description = "Apose.BarCode")]
public void AposeCode()
{
using var generator = new Aspose.BarCode.Generation.BarcodeGenerator(Aspose.BarCode.Generation.EncodeTypes.QR, Version.Data);
generator.Parameters.Barcode.QR.QrErrorLevel = Aspose.BarCode.Generation.QRErrorLevel.LevelM;
generator.Save(Stream.Null, Aspose.BarCode.Generation.BarCodeImageFormat.Png);
}
[Benchmark(Description = "QrCode.Net")]
public Gma.QrCodeNet.Encoding.QrCode GmaQrCodeNet() => new Gma.QrCodeNet.Encoding.QrEncoder().Encode(Version.Data);
[Benchmark(Description = "QrCoder")]
public QRCoder.QRCodeData QrCoder() => QRCoder.QRCodeGenerator.GenerateQrCode(Version.Data, QRCoder.QRCodeGenerator.ECCLevel.Default);
[Benchmark(Description = "SkiaSharp.QrCode")]
public SkiaSharp.QrCode.QRCodeData SkiaSharpQrCode() => SkiaGenerator.CreateQrCode(Version.Data, SkiaSharp.QrCode.ECCLevel.M);
[Benchmark(Description = "ZXing.Net", Baseline = true)]
public ZXing.QrCode.Internal.QRCode ZXingQrCode() => ZXing.QrCode.Internal.Encoder.encode(Version.Data, ZXing.QrCode.Internal.ErrorCorrectionLevel.M);
private static readonly int[][][] ModeErrorLevelVersionCapacityLookup =
[
// Numeric
[
// L
[41, 77, 127, 187, 255, 322, 370, 461, 552, 652, 772, 883, 1022, 1101, 1250, 1408, 1548, 1725, 1903, 2061, 2232, 2409, 2620, 2812, 3057, 3283, 3517, 3669, 3909, 4158, 4417, 4686, 4965, 5253, 5529, 5836, 6153, 6479, 6743, 7089],
// M
[34, 63, 101, 149, 202, 255, 293, 365, 432, 513, 604, 691, 796, 871, 991, 1082, 1212, 1346, 1500, 1600, 1708, 1872, 2059, 2188, 2395, 2544, 2701, 2857, 3035, 3289, 3486, 3693, 3909, 4134, 4343, 4588, 4775, 5039, 5313, 5596],
// Q
[27, 48, 77, 111, 144, 178, 207, 259, 312, 364, 427, 489, 580, 621, 703, 775, 876, 948, 1063, 1159, 1224, 1358, 1468, 1588, 1718, 1804, 1933, 2085, 2181, 2358, 2473, 2670, 2805, 2949, 3081, 3244, 3417, 3599, 3791, 3993],
// H
[17, 34, 58, 82, 106, 139, 154, 202, 235, 288, 331, 374, 427, 468, 530, 602, 674, 746, 813, 919, 969, 1056, 1108, 1228, 1286, 1425, 1501, 1581, 1677, 1782, 1897, 2022, 2157, 2301, 2361, 2524, 2625, 2735, 2927, 3057]
],
// Alphanumeric
[
// L
[25, 47, 77, 114, 154, 195, 224, 279, 335, 395, 468, 535, 619, 667, 758, 854, 938, 1046, 1153, 1249, 1352, 1460, 1588, 1704, 1853, 1990, 2132, 2223, 2369, 2520, 2677, 2840, 3009, 3183, 3351, 3537, 3729, 3927, 4087, 4296],
// M
[20, 38, 61, 90, 122, 154, 178, 221, 262, 311, 366, 419, 483, 528, 600, 656, 734, 816, 909, 970, 1035, 1134, 1248, 1326, 1451, 1542, 1637, 1732, 1839, 1994, 2113, 2238, 2369, 2506, 2632, 2780, 2894, 3054, 3220, 3391],
// Q
[16, 29, 47, 67, 87, 108, 125, 157, 189, 221, 259, 296, 352, 376, 426, 470, 531, 574, 644, 702, 742, 823, 890, 963, 1041, 1094, 1172, 1263, 1322, 1429, 1499, 1618, 1700, 1787, 1867, 1966, 2071, 2181, 2298, 2420],
// H
[10, 20, 35, 50, 64, 84, 93, 122, 143, 174, 200, 227, 259, 283, 321, 365, 408, 452, 493, 557, 587, 640, 672, 744, 779, 864, 910, 958, 1016, 1080, 1150, 1226, 1307, 1394, 1431, 1530, 1591, 1658, 1774, 1852]
],
// Byte
[
// L
[17, 32, 53, 78, 106, 134, 154, 192, 230, 271, 321, 367, 425, 458, 520, 586, 644, 718, 792, 858, 929, 1003, 1091, 1171, 1273, 1367, 1465, 1528, 1628, 1732, 1840, 1952, 2068, 2188, 2303, 2431, 2563, 2699, 2809, 2953],
// M
[14, 26, 42, 62, 84, 106, 122, 152, 180, 213, 251, 287, 331, 362, 412, 450, 504, 560, 624, 666, 711, 779, 857, 911, 997, 1059, 1125, 1190, 1264, 1370, 1452, 1538, 1628, 1722, 1809, 1911, 1989, 2099, 2213, 2331],
// Q
[11, 20, 32, 46, 60, 74, 86, 108, 130, 151, 177, 203, 241, 258, 292, 322, 364, 394, 442, 482, 509, 565, 611, 661, 715, 751, 805, 868, 908, 982, 1030, 1112, 1168, 1228, 1283, 1351, 1423, 1499, 1579, 1663],
// H
[7, 14, 24, 34, 44, 58, 64, 84, 98, 119, 137, 155, 177, 194, 220, 250, 280, 310, 338, 382, 403, 439, 461, 511, 535, 593, 625, 658, 698, 742, 790, 842, 898, 958, 983, 1051, 1093, 1139, 1219, 1273]
],
// Kanji
[
// L
[10, 20, 32, 48, 65, 82, 95, 118, 141, 167, 198, 226, 262, 282, 320, 361, 397, 442, 488, 528, 572, 618, 672, 721, 784, 842, 902, 940, 1002, 1066, 1132, 1201, 1273, 1347, 1417, 1496, 1577, 1661, 1729, 1817],
// M
[8, 16, 26, 38, 52, 65, 75, 93, 111, 131, 155, 177, 204, 223, 254, 277, 310, 345, 384, 410, 438, 480, 528, 561, 614, 652, 692, 732, 778, 843, 894, 947, 1002, 1060, 1113, 1176, 1224, 1292, 1362, 1435],
// Q
[7, 12, 20, 28, 37, 45, 53, 66, 80, 93, 109, 125, 149, 159, 180, 198, 224, 243, 272, 297, 314, 348, 376, 407, 440, 462, 496, 534, 559, 604, 634, 684, 719, 756, 790, 832, 876, 923, 972, 1024],
// H
[4, 8, 15, 21, 27, 36, 39, 52, 60, 74, 85, 96, 109, 120, 136, 154, 173, 191, 208, 235, 248, 270, 284, 315, 330, 365, 385, 405, 430, 457, 486, 518, 553, 590, 605, 647, 673, 701, 750, 784]
]
];
}