{"id":27612570,"url":"https://github.com/energy164/adventofperformance","last_synced_at":"2026-02-05T23:01:15.281Z","repository":{"id":252848918,"uuid":"748411047","full_name":"eNeRGy164/AdventOfPerformance","owner":"eNeRGy164","description":"C# performance optimization techniques via Advent of Code puzzles. Includes benchmarks across multiple .NET versions and Native AOT.","archived":false,"fork":false,"pushed_at":"2025-11-10T19:24:04.000Z","size":3521,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-29T23:57:18.877Z","etag":null,"topics":["benchmark","performance"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eNeRGy164.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-01-25T22:53:52.000Z","updated_at":"2025-11-20T16:16:44.000Z","dependencies_parsed_at":"2025-04-23T01:45:47.183Z","dependency_job_id":"9a20a3d8-9bb0-47fc-bd45-0d088aced745","html_url":"https://github.com/eNeRGy164/AdventOfPerformance","commit_stats":null,"previous_names":["energy164/adventofperformance"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eNeRGy164/AdventOfPerformance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eNeRGy164%2FAdventOfPerformance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eNeRGy164%2FAdventOfPerformance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eNeRGy164%2FAdventOfPerformance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eNeRGy164%2FAdventOfPerformance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eNeRGy164","download_url":"https://codeload.github.com/eNeRGy164/AdventOfPerformance/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eNeRGy164%2FAdventOfPerformance/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29137750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T22:49:08.052Z","status":"ssl_error","status_checked_at":"2026-02-05T22:45:32.059Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","performance"],"created_at":"2025-04-23T01:45:39.087Z","updated_at":"2026-02-05T23:01:15.040Z","avatar_url":"https://github.com/eNeRGy164.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Season for Speed: Turning Puzzles into C# Performance Win\n\nWelcome to the repository accompanying my conference talk \"[A Season for Speed: Turning Puzzles into C# Performance Win](https://sessionize.com/s/michael-hompus/a-season-for-speed-turning-puzzles-into-c-performa/85804)\".\nThis project showcases my journey of solving [Advent of Code](https://adventofcode.com/) puzzles while learning and applying C# performance optimization techniques.\n\n## Presentation\n\nGet the slides I used at previous presentations.\n\n- [VISUG XL](\u003chttps://raw.githubusercontent.com/eNeRGy164/AdventOfPerformance/main/presentations/VisugXL 2024 - A Season for Speed - Turning Puzzles into C%23 Performance Wins.pdf\u003e)\n\n## Getting started\n\n### Prerequisites\n\nEnsure you have the following installed:\n\nFor most benchmarks:\n\n- .NET 8.0 SDK\n\nFor the cross-framework comparison benchmark:\n\n- .NET 8.0 SDK\n- .NET 7.0 SDK\n- .NET 6.0 SDK\n- .NET 5.0 SDK\n- .NET Framework 4.8.1 SDK\n\n### Cloning the repository\n\n```bash\ngit clone https://github.com/eNeRGy164/AdventOfPerformance\ncd AdventOfPerformance\n```\n\n### Running the benchmarks\n\n#### Native AOT\n\nFor running with the Native AOT, as I did for my talk, use:\n\n```bash\ndotnet run -c Release -f net8.0 --framework nativeaot8.0 --filter *\n```\n\nThis takes about 16 minutes on an AMD Ryzen 5 7600.\n\n\u003e [!IMPORTANT]\n\u003e On processors with the `AVX-512F` capability, the current version of [BenchmarkDotNet](https://benchmarkdotnet.org/) (`0.12.3`) may generate invalid code and not work correctly.\n\u003e This issue will be resolved in the next version of BenchmarkDotNet.\n\n#### Without specifying a framework\n\nTo run all the benchmarks, use the following command:\n\n```bash\ndotnet run -c Release -f net8.0 --filter *\n```\n\nThis takes about 16 minutes on an AMD Ryzen 5 7600.\n\n#### Only the puzzle benchmarks\n\nTo run all the benchmarks, use the following command:\n\n```bash\ndotnet run -c Release -f net8.0 --framework nativeaot8.0 --filter AdventOfPerformance.Puzzle*\n```\n\nThis takes about 16 minutes on an AMD Ryzen 5 7600.\n\n#### Only the framework benchmarks\n\n```bash\ndotnet run -c Release -f net8.0 --filter AdventOfPerformance.Framework*\n```\n\nThis takes about 1.5 minutes on an AMD Ryzen 5 7600.\n\n## Benchmark results\n\n### Puzzle part 1\n\n[PuzzlePart1Benchmarks.cs](./AdventOfPerformance/Puzzle/PuzzlePart1Benchmarks.cs)\n\n```plain\nBenchmarkDotNet v0.13.13-nightly.20240601.156, Windows 11 (10.0.22631.3737/23H2/2023Update/SunValley3)\nAMD Ryzen 5 7600, 1 CPU, 12 logical and 6 physical cores\n.NET SDK 8.0.302\n  [Host]     : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI\n  Job-MUAWXP : .NET 8.0.6, X64 NativeAOT AVX-512F+CD+BW+DQ+VL+VBMI\n\nRuntime=NativeAOT 8.0  Toolchain=Latest ILCompiler  \n```\n\n| Method                | Median       | Ratio | Gen0    | Gen1   | Allocated | Alloc Ratio |\n|---------------------- |-------------:|------:|--------:|-------:|----------:|------------:|\n| LinqQuery             | 528,551.5 ns | 1.000 | 62.5000 |      - | 1048328 B |       1.000 |\n| LinqQueryIndex        | 420,219.8 ns | 0.792 | 49.3164 |      - |  830576 B |       0.792 |\n| Foreach               | 185,389.9 ns | 0.349 |  0.4883 |      - |   10472 B |       0.010 |\n| ForeachInnerRange     |  13,049.5 ns | 0.025 |  5.1575 | 0.0153 |   86472 B |       0.082 |\n| For                   |  10,302.7 ns | 0.019 |  0.0458 |      - |     872 B |       0.001 |\n| Pointers              |   6,196.6 ns | 0.012 |       - |      - |         - |       0.000 |\n| IntermediateVariables |   6,055.8 ns | 0.011 |  0.0458 |      - |     872 B |       0.001 |\n| ForGoto               |   5,920.1 ns | 0.011 |  0.0458 |      - |     872 B |       0.001 |\n| Refs                  |   5,567.1 ns | 0.011 |  0.0458 |      - |     824 B |       0.001 |\n| InitializeArray       |   4,394.5 ns | 0.008 |  0.0458 |      - |     824 B |       0.001 |\n| CustomIntParser       |   3,519.3 ns | 0.007 |  0.0458 |      - |     824 B |       0.001 |\n| LowerMemory           |   3,494.3 ns | 0.007 |  0.0229 |      - |     424 B |       0.000 |\n| TwoPointer            |   3,010.2 ns | 0.006 |  0.0496 |      - |     872 B |       0.001 |\n| Hashing               |   1,923.7 ns | 0.004 |  0.2327 |      - |    3944 B |       0.004 |\n| Bits                  |     245.4 ns | 0.000 |  0.0186 |      - |     312 B |       0.000 |\n\n### Puzzle part 2\n\n[PuzzlePart2Benchmarks.cs](./AdventOfPerformance/Puzzle/PuzzlePart2Benchmarks.cs)\n\n```plain\nBenchmarkDotNet v0.13.13-nightly.20240601.156, Windows 11 (10.0.22631.3737/23H2/2023Update/SunValley3)\nAMD Ryzen 5 7600, 1 CPU, 12 logical and 6 physical cores\n.NET SDK 8.0.302\n  [Host]     : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI\n  Job-MUAWXP : .NET 8.0.6, X64 NativeAOT AVX-512F+CD+BW+DQ+VL+VBMI\n\nRuntime=NativeAOT 8.0  Toolchain=Latest ILCompiler  \n```\n\n| Method          | Median        | Ratio | Gen0      | Allocated  | Alloc Ratio |\n|---------------- |--------------:|------:|----------:|-----------:|------------:|\n| LinqQuery       | 18,929.987 μs | 1.000 | 2156.2500 | 36410868 B |       1.000 |\n| CustomIntParser |     63.120 μs | 0.003 |         - |      824 B |       0.000 |\n| TwoPointer      |      3.020 μs | 0.000 |    0.0496 |      872 B |       0.000 |\n\n### Compare frameworks\n\n[FrameworksTestBenchmark.cs](./AdventOfPerformance/OtherStuff/FrameworksTestBenchmark.cs)\n\n```plain\nBenchmarkDotNet v0.13.13-nightly.20240601.156, Windows 11 (10.0.22631.3737/23H2/2023Update/SunValley3)\nAMD Ryzen 5 7600, 1 CPU, 12 logical and 6 physical cores\n.NET SDK 8.0.302\n  [Host]               : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI\n  .NET Framework 4.8.1 : .NET Framework 4.8.1 (4.8.9241.0), X64 RyuJIT VectorSize=256\n  .NET 5.0             : .NET 5.0.17 (5.0.1722.21314), X64 RyuJIT AVX2\n  .NET 7.0             : .NET 7.0.20 (7.0.2024.26716), X64 RyuJIT AVX2\n  .NET 6.0             : .NET 6.0.31 (6.0.3124.26714), X64 RyuJIT AVX2\n  .NET 8.0             : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI\n```\n\n| Method    | Job                  | Runtime              | Median   | Gen0     | Allocated  |\n|---------- |--------------------- |--------------------- |---------:|---------:|-----------:|\n| LinqQuery | .NET Framework 4.8.1 | .NET Framework 4.8.1 | 994.5 μs | 166.0156 | 1026.81 KB |\n| LinqQuery | .NET 5.0             | .NET 5.0             | 491.0 μs |  62.5000 | 1023.76 KB |\n| LinqQuery | .NET 7.0             | .NET 7.0             | 440.3 μs |  62.5000 | 1023.76 KB |\n| LinqQuery | .NET 6.0             | .NET 6.0             | 437.1 μs |  62.5000 | 1023.76 KB |\n| LinqQuery | .NET 8.0             | .NET 8.0             | 294.1 μs |  62.5000 | 1023.76 KB |\n\n### Walking a 2D `Array`\n\n[WalkThroughMultiDimArraysBenchmarks.cs](./AdventOfPerformance/OtherStuff/WalkThroughMultiDimArraysBenchmarks.cs)\n\n```plain\nBenchmarkDotNet v0.13.13-nightly.20240601.156, Windows 11 (10.0.22631.3737/23H2/2023Update/SunValley3)\nAMD Ryzen 5 7600, 1 CPU, 12 logical and 6 physical cores\n.NET SDK 8.0.302\n  [Host]     : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI\n  Job-MUAWXP : .NET 8.0.6, X64 NativeAOT AVX-512F+CD+BW+DQ+VL+VBMI\n\nRuntime=NativeAOT 8.0  Toolchain=Latest ILCompiler  \n```\n\n| Method                                    | Median   | Allocated |\n|------------------------------------------ |---------:|----------:|\n| 'Walk through 2D Array, column by column' | 233.8 μs |         - |\n| 'Walk through 2D Array, row by row'       | 138.7 μs |         - |\n| 'Use enumerator of the 2D Array'          | 122.9 μs |         - |\n\n### Writing a 2D `Array`\n\n[SerializeMultiDimArraysBenchmarks.cs](./AdventOfPerformance/OtherStuff/SerializeMultiDimArraysBenchmarks.cs)\n\n```plain\nBenchmarkDotNet v0.13.13-nightly.20240601.156, Windows 11 (10.0.22631.3737/23H2/2023Update/SunValley3)\nAMD Ryzen 5 7600, 1 CPU, 12 logical and 6 physical cores\n.NET SDK 8.0.302\n  [Host]     : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI\n  Job-MUAWXP : .NET 8.0.6, X64 NativeAOT AVX-512F+CD+BW+DQ+VL+VBMI\n\nRuntime=NativeAOT 8.0  Toolchain=Latest ILCompiler  \n```\n\n| Method                | Median   | Gen0     | Gen1     | Gen2     | Allocated  |\n|---------------------- |---------:|---------:|---------:|---------:|-----------:|\n| WriteCharYX           | 636.8 μs | 166.0156 | 166.0156 | 166.0156 | 1031.03 KB |\n| WriteCharForeach      | 584.4 μs | 166.0156 | 166.0156 | 166.0156 | 1031.03 KB |\n| WriteCharStringCreate | 403.1 μs | 166.5039 | 166.5039 | 166.5039 |  512.08 KB |\n| WriteCharSpan         | 195.2 μs | 166.5039 | 166.5039 | 166.5039 |  512.08 KB |\n\n### Parsing input\n\n[InputParseBenchmarks.cs](./AdventOfPerformance/OtherStuff/InputParseBenchmarks.cs)\n\n```plain\nBenchmarkDotNet v0.13.13-nightly.20240601.156, Windows 11 (10.0.22631.3737/23H2/2023Update/SunValley3)\nAMD Ryzen 5 7600, 1 CPU, 12 logical and 6 physical cores\n.NET SDK 8.0.302\n  [Host]     : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI\n  Job-MUAWXP : .NET 8.0.6, X64 NativeAOT AVX-512F+CD+BW+DQ+VL+VBMI\n\nRuntime=NativeAOT 8.0  Toolchain=Latest ILCompiler  \n```\n\n| Method            | Median    | Ratio | Gen0     | Gen1    | Allocated | Alloc Ratio |\n|------------------ |----------:|------:|---------:|--------:|----------:|------------:|\n| Regex             | 484.23 μs |  1.00 | 103.0273 | 12.6953 | 1683.3 KB |        1.00 |\n| RegexGenerated    | 343.51 μs |  0.71 | 103.0273 | 12.6953 | 1683.3 KB |        1.00 |\n| CharSplit         | 236.39 μs |  0.49 |  51.2695 |  6.3477 | 840.38 KB |        0.50 |\n| CharsSplit        | 137.35 μs |  0.28 |  34.1797 |  4.1504 | 560.55 KB |        0.33 |\n| Spans             |  32.04 μs |  0.07 |   2.1362 |       - |  35.11 KB |        0.02 |\n| SpansAnalyzeInput |  10.69 μs |  0.02 |   2.1362 |       - |  35.11 KB |        0.02 |\n\n### Creating objects and storing in a `HashSet`\n\n[CreateObjectsInHashSetBenchmark.cs](./AdventOfPerformance/OtherStuff/CreateObjectsInHashSetBenchmark.cs)\n\n```plain\nBenchmarkDotNet v0.13.13-nightly.20240601.156, Windows 11 (10.0.22631.3737/23H2/2023Update/SunValley3)\nAMD Ryzen 5 7600, 1 CPU, 12 logical and 6 physical cores\n.NET SDK 8.0.302\n  [Host]     : .NET 8.0.6 (8.0.624.26715), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI\n  Job-MUAWXP : .NET 8.0.6, X64 NativeAOT AVX-512F+CD+BW+DQ+VL+VBMI\n\nRuntime=NativeAOT 8.0  Toolchain=Latest ILCompiler  \n```\n\n| Method                                                                 | Median   | Ratio | Gen0    | Gen1    | Gen2    | Allocated | Alloc Ratio |\n|----------------------------------------------------------------------- |---------:|------:|--------:|--------:|--------:|----------:|------------:|\n| 'Class w/ properties assigned in ctor'                                 | 139.1 μs |  1.00 | 49.8047 | 49.8047 | 49.8047 | 314.64 KB |        1.00 |\n| 'Struct w/ readonly fields assigned in ctor'                           | 136.5 μs |  0.98 | 49.8047 | 49.8047 | 49.8047 | 314.92 KB |        1.00 |\n| 'Readonly Struct w/ properties assigned in ctor'                       | 135.6 μs |  0.97 | 49.8047 | 49.8047 | 49.8047 | 314.92 KB |        1.00 |\n| 'Struct w/ properties assigned in the ctor'                            | 135.1 μs |  0.97 | 49.8047 | 49.8047 | 49.8047 | 314.92 KB |        1.00 |\n| 'Sealed Class w/ properties assigned in ctor'                          | 134.5 μs |  0.96 | 49.8047 | 49.8047 | 49.8047 | 314.64 KB |        1.00 |\n| 'Class w/ fields assigned in the ctor'                                 | 133.6 μs |  0.96 | 49.8047 | 49.8047 | 49.8047 | 314.64 KB |        1.00 |\n| 'Readonly Struct w/ '[in]' properties assigned in ctor'                | 133.7 μs |  0.96 | 49.8047 | 49.8047 | 49.8047 | 314.92 KB |        1.00 |\n| 'Record Class w/ properties assigned via primary ctor'                 | 127.3 μs |  0.91 | 49.8047 | 49.8047 | 49.8047 | 314.64 KB |        1.00 |\n| 'Sealed Record Class w/ properties assigned via the primary ctor'      | 127.0 μs |  0.91 | 49.8047 | 49.8047 | 49.8047 | 314.64 KB |        1.00 |\n| 'Readonly Record Class w/ '[in]' properties assigned via primary ctor' | 104.3 μs |  0.75 | 49.9268 | 49.9268 | 49.9268 | 197.45 KB |        0.63 |\n| 'Readonly Record Struct w/ properties assigned via primary ctor'       | 103.6 μs |  0.74 | 49.9268 | 49.9268 | 49.9268 | 197.45 KB |        0.63 |\n| 'Record Struct w/ properties assigned via primary ctor'                | 103.6 μs |  0.74 | 49.9268 | 49.9268 | 49.9268 | 197.45 KB |        0.63 |\n\n\n## Contributing\n\nFeel free to submit issues or pull requests if you have suggestions or improvements.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenergy164%2Fadventofperformance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenergy164%2Fadventofperformance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenergy164%2Fadventofperformance/lists"}