Skip to content

About

.NET benchmarks for query building, LINQ, collections, serialization, and other implementation choices

Resources

Stars

21 stars

Watchers

2 watching

Forks

Repository files navigation

CuriousBenchmarks icon

Contributors Forks Stargazers Issues MIT License LinkedIn

GitHub last commit CI Benchmarks Results codecov


Logo

Curious Benchmarks

A repository housing targeted investigations and performance analyses of various .NET development approaches, offering developers insights into optimization techniques and architectural decisions.
Explore the benchmark results »

Results dashboard · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Results
  4. CI & results
  5. Usage
  6. Roadmap
  7. Contributing
  8. License
  9. Contact
  10. Acknowledgments
Benchmarks Table of Contents
  1. Enum boxing-unboxing benchmarks
  2. Comparison Length check methods of collections
  3. Comparing GroupBy/Distinct/DistinctBy for getting unique items
  4. Comparing different iterators (for,foreach, linq, ref foreach, etc.)
  5. Comparing different string link formatting, dashing for dash view, concatenating and generating unique string
  6. Json Serialization/Deserialization
  7. Binary Serialization/Deserialization
  8. Sort array of T by ids from string array
  9. [WIP] String Manipulations
  10. Model flattening
  11. A new stopwatch approach
  12. URL Concat and Query building

About The Project

A curated collection of in-depth studies exploring various .NET development approaches, focusing on performance optimization and best practices. This repository houses detailed investigations into different techniques, architectural patterns, and implementation strategies within the .NET ecosystem. Each analysis aims to provide developers with valuable insights to enhance application efficiency and make informed decisions when designing .NET solutions.

(back to top)

Built With

.NET

(back to top)

Results

Up-to-date results for every benchmark live on the dashboard: antomys.github.io/CuriousBenchmarks. It shows the latest run, what got slower or faster since the previous run, .NET 10 vs .NET 11, Ubuntu vs Windows vs macOS, and the history of any single benchmark. Lower is better everywhere; numbers come from shared GitHub-hosted runners, so treat small changes as noise and check the trend before drawing conclusions.

CI & results

Workflow Trigger What it does
ci.yml push / PR to master Reports all six ubuntu, macos, windows × net10.0, net11.0 jobs, including docs-only changes; docs-only runs skip setup, restore, build and test. Full runs build the solution and upload coverage to Codecov; partial runs build the test project (referencing 11 of 12 benchmark suites) and run the selected tests. Coverage policy is in codecov.yml.
benchmarks.yml code push to master, automatic or manual dispatch Pushes select affected suites using package version differences and direct/transitive project dependencies; if none are affected, publishing is skipped. Shared build changes or an uncertain selection run all suites. On master, a cancellation that may have dropped queued work triggers the full suite, OS and TFM matrix until a non-dry publishing run succeeds. Unavailable history also triggers the full matrix. Topic-branch dispatches use their explicit inputs. Results are ingested into docs/data, committed to master ([skip ci]) and redeployed to Pages. Manual runs can select job (dry/short/medium), suites, OS and TFM.
pages.yml changes to site/, docs/data/, scripts/ Tests the data scripts, validates and redeploys the dashboard (PRs: validation only).
benchmark-triggers.yml daily at 04:41 UTC, manual (optional dry run) Checks the .NET release index. If a covered runtime is newer than the highest real measurement, or has none yet, it requests a full run on master with both TFMs at the same commit. Samples and smoke tests do not count. Any active benchmark run on master defers dispatch until the next check. Only a completed, non-cancelled Benchmarks (dotnet-runtime) dispatch on master created on or after the release counts as a prior attempt; completed push runs and unmarked dispatches (including partial Dependabot runs) do not. If the runtime is still unmeasured, inspect the linked attempt and use force=true to retry. A supported GA channel above the highest covered major gets a matrix-update issue instead.
dependabot-automerge.yml CI (ci.yml) completed for a PR Squash-merges a Dependabot PR only if the latest CI run for its head SHA succeeded with the changes job and all six matrix jobs green, the PR has exactly one verified Dependabot commit whose updates are all semver-patch or semver-minor, and every other check/status (e.g. codecov/project) succeeded; the merge is pinned to that SHA. Because a GITHUB_TOKEN merge triggers no push workflows, it checks out master after merge (never the PR head) and runs only suites that use an updated package, directly or through a referenced project. Action bumps and test-only packages need no benchmarks; if suite selection fails, all suites run.

Data flow: each benchmark leg runs BenchmarkDotNet, then scripts/verify-bdn.mjs fails the leg if no *-report-full-compressed.json was produced or a case has no statistics; the report plus a small environment manifest is uploaded either way (raw output is kept 3 days, the repository's artifact-retention cap). A read-only ingest job runs scripts/ingest.mjs with the planned matrix: a leg's identity comes from its artifact name (bdn-<os>-<tfm>-<suite>) and must be planned, a missing or mismatching manifest makes it a failed leg, and planned legs without an artifact are recorded as missing. It appends one immutable source record per workflow run attempt under docs/data/sources/ (replaying the same attempt is a no-op if identical and an error otherwise), then regenerates the derived runs/ (comparison with the previous run of the same BenchmarkDotNet job, flagged only beyond max(5 %, 2 × error); dry runs are smoke tests and never a baseline), index.json, latest.json and trends/, and validates everything with scripts/check-site.mjs. Only then does the commit job — the only job with contents: write, and only on master with publishing enabled — re-ingest on the branch tip, re-validate and push; the Pages artifact is built from that commit and deployed only if its upload succeeded. See docs/data/README.md for the data format, re-runs and --prune compaction.

Results are pushed to master with the workflow's GITHUB_TOKEN, which works because master is not protected. If branch protection or a ruleset is enabled later, keep the protection and either add the GitHub Actions app (github-actions) to the ruleset's bypass list for docs/data/** results commits, or push with a dedicated GitHub App installation token (e.g. actions/create-github-app-token) whose app is allowed to bypass; otherwise the commit job fails with "Could not push results to master" and nothing is deployed. Do not weaken the protection or give other jobs write access.

Preview the dashboard locally from the repository root with python -m http.server (or any static server) and open http://localhost:8000/site/; on localhost only, ?data=<relative path> points it at another data folder. Validate with node scripts/check-site.mjs and node --test scripts/test/; node scripts/build-site.mjs --out _site assembles the Pages artifact (it refuses any output directory other than a _name folder in the canonical repository root or below the canonical temp directory, and any path through a symbolic link or junction).

(back to top)

Getting Started

Prerequisites

Install the .NET 11.0.100 SDK. It builds both target frameworks; the .NET 10 SDK is not required. To run the suites on both frameworks, install the .NET 10 runtime alongside the .NET 11 runtime included with the SDK. Check dotnet --list-runtimes for both Microsoft.NETCore.App 10.x and 11.x. For QueryBuilder, also install the matching ASP.NET Core shared frameworks (Microsoft.AspNetCore.App 10.x and 11.x). BenchmarkDotNet is restored with the solution.

Build suite Dockerfiles from the repository root. They retain the .NET 11 SDK so BenchmarkDotNet can compile its harness and include both shared frameworks for the selected target. Set --build-arg DOTNET_VERSION=11.0 to target .NET 11 instead of the default .NET 10.

Installation

From a terminal:

git clone https://github.com/antomys/CuriousBenchmarks.git
cd CuriousBenchmarks
dotnet restore Benchmarks.sln
dotnet build Benchmarks.sln -c Release --no-restore

Usage

From the repository root, choose a suite and specify the framework with -f. For example, smoke-test the same suite on each runtime:

dotnet run -c Release -f net10.0 --project src/main/Benchmarks.Enum -- --filter '*' --job dry --exporters json
dotnet run -c Release -f net11.0 --project src/main/Benchmarks.Enum -- --filter '*' --job dry --exporters json

With no suite arguments, all cases run without prompting (equivalent to --filter '*'); Docker images use the same default. When supplying options such as --job dry, include --filter '*' to select all cases non-interactively. The process exits with a non-zero code if a benchmark report fails or BenchmarkDotNet finds critical validation errors.

The dry job checks that cases execute; use --job short for measurements. BenchmarkDotNet prints a summary and writes reports under BenchmarkDotNet.Artifacts/results/. Add --artifacts <directory> after -- to keep the two runs separate.

SortArrayByArray stops at 10,000 items by default. Set BENCH_SORT_LARGE=1 before launching it to include 100,000 items; even a dry case at that size can take more than 35 minutes.

Known limitations

  • Benchmark runs with no summaries (for example, an unmatched filter or invalid arguments) exit non-zero. Informational requests (--list, --info, --help, --version) can succeed without running benchmarks.
  • BenchmarkDotNet 0.15.8 recognizes runtimes only through .NET 10. The net11.0 suites fix the generated process to the out-of-process .NET 11 toolchain and disable parallel benchmark builds. Toolchain selectors (--inProcess / -i, --cli, --runtimes / -r including NativeAOT, --coreRun, --clrVersion, --monoPath, and --ilCompilerVersion) are rejected rather than silently overridden. Remove those options or use a net10.0 suite build. CLI jobs such as --job dry still apply.
  • QueryBuilder now uses QueryHelpers and QueryBuilder from the Microsoft.AspNetCore.App shared framework (ASP.NET Core 10 or 11, matching the TFM), rather than the Microsoft.AspNetCore.Http.Extensions 2.3.9 and Microsoft.AspNetCore.WebUtilities 9.0.14 packages. Keep that version change in mind when comparing results with older runs.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Ihor Volokhovych - @deqque13 - igorvolokhovych@gmail.com

Project Link: https://github.com/antomys/CuriousBenchmarks

(back to top)

Acknowledgments

  • Volodymyr Lyshenko
    • Volodymyr has been instrumental in expanding the scope of our performance analyses by proposing numerous innovative and insightful benchmark scenarios. His suggestions have led to the inclusion of several new benchmarks that explore previously unexamined aspects of .NET performance.
    • Through creative input, Volodymyr has helped broaden the range of .NET approaches and techniques covered in this repository, making it a more comprehensive resource for the developer community.
  • pro.net Telegram chat
    • The members of pro.net Telegram chat have provided thorough reviews of benchmarks, offering critical insights that have significantly improved the quality and reliability of performance analyses.
    • Their innovative suggestions have led to the inclusion of new benchmark scenarios and the refinement of existing ones, broadening the scope and relevance of our investigations.
    • On numerous occasions, pro.net Telegram chat experts have shared their deep knowledge of .NET internals, helping us understand and explain complex performance behaviors observed in our benchmarks.

(back to top)

About

.NET benchmarks for query building, LINQ, collections, serialization, and other implementation choices

Resources

Stars

21 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages