microbenchmarking
できること
このスキルは、.NETのコードの小さな部分がどれだけ速く動くかを測るBenchmarkDotNetのベンチマークを、書いたりレビューしたりする作業を導きます。特定のメソッドや変更について、信頼できる計測がほしい開発者のためのものです。
使う場面
- ✓.NETの小さなコードがどれだけ速く動くかを測りたいとき。
- ✓BenchmarkDotNetのベンチマークを書いたり、レビューしたりする必要があるとき。
- ✓二つの実装を、適切な計測で比べたいとき。
スキルのリンク
https://github.com/dotnet/skills/blob/main/plugins/dotnet-diag/skills/microbenchmarking/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私のC#のコードで、整数を解析する二つの方法を比べるBenchmarkDotNetのベンチマークを書いてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは現在のベンチマークの指針を読み、適切なジョブの設定とパラメータを使ってベンチマークを書き、実行前に一般的な誤りに照らして設定を確認します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Benchmark Authoring Guidelines
BenchmarkDotNet (BDN) is a .NET library for writing and running microbenchmarks. Throughout this skill, "BDN" refers to BenchmarkDotNet.
Note: Evaluations of LLMs writing BenchmarkDotNet benchmarks have revealed common failure patterns caused by outdated assumptions about BDN's behavior — particularly around runtime comparison, job configuration, and execution defaults that have changed in recent versions. The reference files in this skill contain verified, current information. You MUST read the reference files relevant to the task before writing any code — your training data likely contains outdated or incorrect BDN patterns.
Key concepts
- Job — describes how to run a benchmark: runtime, iteration counts, launch count, run strategy, and environment settings. Multiple jobs can be configured to run the same benchmarks under different conditions.
- Benchmark case — one method × one parameter combination × one job. The atomic unit BDN measures.
- Operation — the logical unit of work being measured. All BDN output columns (Mean, Error, etc.) report time per operation.
- Invocation — a single call to the benchmark method. By default, 1 invocation = 1 operation. With
OperationsPerInvoke=N, each invocation counts as N operations. - Iteration — a timed batch of invocations. BDN measures the total time for all invocations in an iteration, then divides by the total operation count to get per-operation time.
Benchmarks are comparative instruments
A single benchmark number has limited value — it can confirm the order of magnitude of a measurement, but the exact value changes across machines, operating systems, and runtime configurations. Benchmarks produce the most useful information when compared against something. Before writing benchmarks, identify the comparison axis for the current task:
- Approaches (A vs B): comparing alternative implementations side-by-side in the same run.
- Runtimes: comparing the same code across .NET versions (e.g., net8.0 vs net9.0).
- Package versions: comparing different versions of a NuGet dependency.
- Builds (before/after): comparing a saved DLL of the old code against the current source.
- Runtime configuration (GC mode, JIT settings): understanding how runtime settings affect performance — compared via multiple jobs in a single run.
- Scale (N=100 vs N=1000): understanding how performance changes as input size grows.
- Hardware/OS: comparing across different machines or operating systems — requires separate runs on each environment.
- Historical measurements: comparing against measurements recorded at a previous point in time.
BDN can compare the first six axes side-by-side in a single run, but each requires specific CLI flags or configuration that differ from what you might expect — read references/comparison-strategies.md for the correct approach for each strategy before configuring a comparison.
Use cases and benchmark lifecycle
There are four distinct reasons a developer writes a benchmark, and each one changes how the benchmark should be designed and where it should live:
Coverage suite: Write benchmarks to maximize coverage of real-world usage patterns so that regressions affecting most users are caught. These benchmarks are permanent — they belong in the project's benchmark suite, follow its conventions (directory structure, base classes, naming), and are checked in.
Issue investigation: Someone has reported a specific performance problem. Write benchmarks to reproduce and diagnose that specific issue. These benchmarks are task-scoped — they persist across the investigation (reproduce → isolate → verify fix) but are not part of the permanent suite.
Change validation: A developer has a PR or change and wants to understand its performance characteristics before merging. These benchmarks are task-scoped — they persist across the review cycle but are not checked in.
Development feedback: A developer is actively working on a task and wants to use benchmarks to evaluate approaches and get information early. These benchmarks are task-scoped and throwaway — they persist across the development session but are deleted when the decision is made.
For use case 1, add to the existing benchmark project following its conventions. For use cases 2–4, create a standalone project in a working directory that persists
よくある質問
ストップウォッチで測ればよいのでは?
BenchmarkDotNetはウォームアップ、繰り返しの実行、ノイズを扱うため、数値がより信頼できます。
よくある誤りを確認しますか?
はい。ランタイムの比較とジョブの設定でのよくある誤りを扱います。
BenchmarkDotNetは必須ですか?
はい。このスキルは、.NETのベンチマークのためにそのライブラリを中心に作られています。
詳細
作者による元の説明
Activate this skill when BenchmarkDotNet (BDN) is involved in the task — creating, running, configuring, or reviewing BDN benchmarks. Also activate when microbenchmarking .NET code would be useful and BenchmarkDotNet is the likely tool. Consider activating when answering a .NET performance question requires measurement and BenchmarkDotNet may be needed. Covers microbenchmark design, BDN configuration and project setup, how to run BDN microbenchmarks efficiently and effectively, and using BDN for side-by-side performance comparisons. Do NOT use for profiling/tracing .NET code (dotnet-trace, Per
repo: dotnet/skills
人気
- GitHubのスター
- 5.8k
- ランキング
- #14579
- ライセンス
- MIT
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
create-custom-agent
5.8kVisual Studio Codeのカスタムエージェントのファイルを、独自のツール、指示、ほかのエージェントへの引き継ぎとともに作るようエージェントを支援します。
create-skill
5.8k有効な名前、明確な発動の説明、規格に従うSKILL.mdファイルを持つ、新しいエージェントのスキルを作るようエージェントを支援します。
csharp-scripts
5.8k.NETのコマンドラインツールを使って、完全なプロジェクトを作らずに、小さなC#のプログラムを一つのファイルとして実行するようエージェントを支援します。
dotnet-pinvoke
5.8k署名、文字列の扱い、メモリ、安全なハンドルを含めて、ネイティブのC言語またはC++のライブラリを.NETから正しく呼び出すようエージェントを支援します。
似ているスキル
test-driven-development
311k機能や修正を作る前に、まず失敗するテストを書き、それが失敗するのを確認してから、合格させる最小のコードを書くようエージェントに教えます。
verification-before-completion
311kタスク、修正、ビルドが完了した、または合格したと主張する前に、実際のチェックを実行し、その出力を読むようエージェントに教えます。
migrate-to-shoehorn
310kテストファイル内の危険な型キャストを、shoehornライブラリに置き換え、テストが部分的なデータを使いつつ型チェックを通るようにします。