Skip to content

Update switch vs if-else performance sample to .NET 11 - #2446

Merged
vladimir-pecanac-main merged 4 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/109820-csharp-switch-vs-if-else-performance
Dec 2, 2026
Merged

vladimir-pecanac-main merged 4 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/109820-csharp-switch-vs-if-else-performance

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Moves the SwitchVsIfElse sample to net11.0 and BenchmarkDotNet 0.15.8 with InProcess on both benchmark classes. Every benchmark now returns a sum of its results, because the old methods discarded them and the JIT removed most of the work being measured. The input array is built in a GlobalSetup method, the if-else shape classifier uses declaration patterns, the unused N parameter is gone, and two Examples classes hold the methods the article prints so they compile as shown.

Target net11.0 with BenchmarkDotNet 0.15.8 and [InProcess]. Every benchmark now
returns its result so the JIT cannot remove the measured work, input is built in
[GlobalSetup], the if-else classifier uses declaration patterns, the unused N
parameter is removed, and the article's example methods are added as compilable
Examples classes.
@vladimir-pecanac-main
vladimir-pecanac-main merged commit ab449bb into CodeMazeBlog:main Dec 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant