microbenchmarking
Fungsinya
Skill ini memandu penulisan dan peninjauan benchmark BenchmarkDotNet, yaitu alat untuk mengukur seberapa cepat bagian kecil kode .NET berjalan. Skill ini untuk pengembang yang ingin pengukuran waktu yang andal untuk satu metode atau perubahan tertentu.
Kapan dipakai
- βSaat Anda ingin mengukur seberapa cepat sepotong kecil kode .NET berjalan.
- βSaat Anda perlu menulis atau meninjau benchmark BenchmarkDotNet.
- βSaat Anda ingin membandingkan dua implementasi dengan pengukuran yang layak.
Link skill
https://github.com/dotnet/skills/blob/main/plugins/dotnet-diag/skills/microbenchmarking/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βTulis benchmark BenchmarkDotNet yang membandingkan dua cara mengurai bilangan bulat di kode C# saya.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Agent membaca panduan benchmark terbaru, menulis benchmark dengan pengaturan job dan parameter yang tepat, lalu memeriksa pengaturannya terhadap kesalahan umum sebelum dijalankan.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum
Mengapa tidak memakai stopwatch saja?
BenchmarkDotNet menangani pemanasan, pengulangan, dan derau, sehingga angkanya lebih andal.
Apakah skill ini memeriksa kesalahan umum?
Ya. Skill ini mencakup kesalahan umum dalam perbandingan runtime dan pengaturan job.
Apakah BenchmarkDotNet wajib dipakai?
Ya. Skill ini dibangun di sekitar pustaka itu untuk benchmark .NET.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 5.8k
- Peringkat
- #14579
- Lisensi
- MIT
- Diperbarui
- 2/11/2026
Komentar
- β¦
Skill lain dari repositori ini
create-custom-agent
5.8kMembantu agent Anda membuat file agen kustom VS Code dengan alatnya sendiri, instruksi, dan serah terima ke agent lain.
create-skill
5.8kMembantu agent Anda membuat skill agent baru dengan nama yang valid, deskripsi pemicu yang jelas, dan file SKILL.md yang mengikuti standar.
csharp-scripts
5.8kMembantu agent Anda menjalankan program C# kecil sebagai satu file dengan alat baris perintah .NET, tanpa membuat proyek lengkap.
dotnet-pinvoke
5.8kMembantu agent Anda memanggil pustaka native C atau C++ dari .NET dengan benar, mencakup tanda tangan, penanganan string, memori, dan safe handle.
Skill serupa
test-driven-development
311kMengajari agent Anda menulis tes yang gagal dulu, melihatnya gagal, lalu menulis kode terkecil yang lulus, sebelum membangun fitur atau perbaikan apa pun.
verification-before-completion
311kMengajari agent Anda menjalankan pemeriksaan nyata dan membaca keluarannya sebelum menyatakan tugas, perbaikan, atau build sudah selesai atau lulus.
migrate-to-shoehorn
310kMengganti type cast berisiko di file tes Anda dengan pustaka shoehorn, sehingga tes bisa memakai data parsial dan tetap lulus pemeriksaan tipe.