Add benchmarking by Shane32 · Pull Request #508 · Shane32/QRCoder
Summary
This PR adds a benchmarking project to the solution so that performance gains during optimizations may be analyzed.
What existing problem does the pull request solve?
It is difficult to quantify the gains from applying performance optimizations without benchmarks.
Sample Output
BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.4291/22H2/2022Update)
13th Gen Intel Core i9-13900K, 1 CPU, 32 logical and 24 physical cores
.NET SDK 8.0.202
[Host] : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
|---|---|---|---|---|---|---|
| CreateQRCode | 245.4 us | 4.88 us | 5.80 us | 17.0898 | 0.2441 | 317.99 KB |
| CreateQRCodeLong | 7,531.1 us | 34.13 us | 31.92 us | 265.6250 | 15.6250 | 4920.13 KB |
Legend
| Term | Description |
|---|---|
| Mean | Arithmetic mean of all measurements |
| Error | Half of 99.9% confidence interval |
| StdDev | Standard deviation of all measurements |
| Gen0 | GC Generation 0 collects per 1000 operations |
| Gen1 | GC Generation 1 collects per 1000 operations |
| Allocated | Allocated memory per single operation (managed only, inclusive, 1KB = 1024B) |
| 1 us | 1 Microsecond (0.000001 sec) |
Observations
Creating the QR code uses a lot of RAM, which triggers garbage collections more frequently. Minimizing the number of garbage collections through a more efficient QR code algorithm can significantly enhance the stability and performance of an ASP.NET Core application. By optimizing the QR code generation process, the application can manage memory better, reduce latency, and handle higher user loads with greater reliability, ultimately improving user experience and application scalability.
Similar benefits would be realized for other targets, such as blazor/webassembly.
Notes
This project targets .NET 8 so that any performance benefits are measured for a developer targeting the latest version of .NET. The compilation targets for the main project have not changed; however, the .NET 8 SDK was added to the CI workflows so that building the solution does not cause a build error.