<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/enum-hasflag-performance-with-benchmarkdotnet-5bm7oppa3" -->

---
title: Enum.HasFlag performance with BenchmarkDotNet | daily.dev
description: Using BenchmarkDotNet, a .NET console app compares the performance of Enum.HasFlag against a bitwise comparison operator for checking flagged enum values. On...
canonical: https://daily.dev/posts/enum-hasflag-performance-with-benchmarkdotnet-5bm7oppa3
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Enum.HasFlag performance with BenchmarkDotNet | daily.dev
og:description: Using BenchmarkDotNet, a .NET console app compares the performance of Enum.HasFlag against a bitwise comparison operator for checking flagged enum values. On...
og:url: https://daily.dev/posts/enum-hasflag-performance-with-benchmarkdotnet-5bm7oppa3
og:image: https://api.daily.dev/og/posts/5bm7oPPA3.png
og:image:alt: Enum.HasFlag performance with BenchmarkDotNet
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Enum.HasFlag performance with BenchmarkDotNet

**[Code4IT](https://daily.dev/sources/code4it)** · 7 min read · 0 upvotes · 0 comments

## Summary

Using BenchmarkDotNet, a .NET console app compares the performance of Enum.HasFlag against a bitwise comparison operator for checking flagged enum values. On .NET Core 3.1, both approaches perform nearly identically regardless of array size (50, 100, or 200 items). However, testing across multiple runtimes reveals that on .NET 4.6.1, HasFlag is more than twice as slow as the bitwise check (9,356 ns vs 3,807 ns at size 200), while on .NET Core 3.1 the gap disappears (923 ns vs 918 ns). The historical slowness was fixed via a RyuJIT optimization documented back in 2017, meaning the long-standing advice to avoid HasFlag for performance no longer applies on modern .NET runtimes.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.code4it.dev/blog/hasflag-performance-benchmarkdotnet>

## Questions this post answers

### Is Enum.HasFlag slower than using bitwise comparison in C#?

On .NET Core 3.1, Enum.HasFlag and bitwise comparison perform nearly identically, around 290 ns for small arrays and scaling similarly up to 200 items. On older .NET 4.6.1, HasFlag was more than twice as slow as bitwise comparison (9,356 ns vs 3,807 ns for 200 items), but this was fixed by a RyuJIT JIT compiler optimization.

_daily.dev surfaces performance deep dives like this for developers deciding between C# enum comparison techniques._

### How do I benchmark .NET code across multiple target frameworks with BenchmarkDotNet?

Install the C++ Desktop libraries via the Visual Studio installer, change TargetFramework to TargetFrameworks in the csproj with a semicolon-separated list (e.g. netcoreapp3.1;net461), and decorate the benchmark class with multiple SimpleJob attributes specifying each RuntimeMoniker. Running the project then executes benchmarks across all specified runtimes for comparison.

_developers comparing runtime performance can track BenchmarkDotNet setup guides like this on daily.dev._

## Similar posts on daily.dev

- [C\# Enum Flags: Combining Values with Bitwise Operations](https://daily.dev/posts/c-enum-flags-combining-values-with-bitwise-operations-dzb7h7dhx) · We Are .NET · 2 upvotes · 0 comments
- [Replacing a Rust Enum with a 64-bit Word Made My Interpreter 17% Faster](https://daily.dev/posts/replacing-a-rust-enum-with-a-64-bit-word-made-my-interpreter-17-faster-vl1pbon5a) · Pointers Gone Wild · 7 upvotes · 1 comments

---

Tags: [#performance](https://daily.dev/tags/performance), [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/enum-hasflag-performance-with-benchmarkdotnet-5bm7oppa3)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Enum.HasFlag performance with BenchmarkDotNet","url":"https://daily.dev/posts/enum-hasflag-performance-with-benchmarkdotnet-5bm7oppa3","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/enum-hasflag-performance-with-benchmarkdotnet-5bm7oppa3"},"datePublished":"2026-10-04T13:07:15.875Z","dateModified":"2026-10-04T13:19:11.989Z","description":"Using BenchmarkDotNet, a .NET console app compares the performance of Enum.HasFlag against a bitwise comparison operator for checking flagged enum values. On...","image":"https://media.daily.dev/image/upload/s--foaA6JGU--/f_auto/v1722860399/public/Placeholder%2004","thumbnailUrl":"https://media.daily.dev/image/upload/s--foaA6JGU--/f_auto/v1722860399/public/Placeholder%2004","isAccessibleForFree":true,"articleSection":"Code4IT","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Code4IT","logo":"https://media.daily.dev/image/upload/s--OaaG4G10--/f_auto,q_auto/v1791119049/logos/code4it?_a=BAMAMicg0","url":"https://daily.dev/sources/code4it"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/enum-hasflag-performance-with-benchmarkdotnet-5bm7oppa3","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"performance,.net,c#","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Code4IT","item":"https://daily.dev/sources/code4it"},{"@type":"ListItem","position":3,"name":"Enum.HasFlag performance with BenchmarkDotNet"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/enum-hasflag-performance-with-benchmarkdotnet-5bm7oppa3#faq","mainEntity":[{"@type":"Question","name":"Is Enum.HasFlag slower than using bitwise comparison in C#?","acceptedAnswer":{"@type":"Answer","text":"On .NET Core 3.1, Enum.HasFlag and bitwise comparison perform nearly identically, around 290 ns for small arrays and scaling similarly up to 200 items. On older .NET 4.6.1, HasFlag was more than twice as slow as bitwise comparison (9,356 ns vs 3,807 ns for 200 items), but this was fixed by a RyuJIT JIT compiler optimization. daily.dev surfaces performance deep dives like this for developers deciding between C# enum comparison techniques."}},{"@type":"Question","name":"How do I benchmark .NET code across multiple target frameworks with BenchmarkDotNet?","acceptedAnswer":{"@type":"Answer","text":"Install the C++ Desktop libraries via the Visual Studio installer, change TargetFramework to TargetFrameworks in the csproj with a semicolon-separated list (e.g. netcoreapp3.1;net461), and decorate the benchmark class with multiple SimpleJob attributes specifying each RuntimeMoniker. Running the project then executes benchmarks across all specified runtimes for comparison. developers comparing runtime performance can track BenchmarkDotNet setup guides like this on daily.dev."}}]}
```

