generated from codebeltnet/dotnet-new-classlib
-
Notifications
You must be signed in to change notification settings - Fork 0
V1.0.0/benchmarkdotnet api #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
948e28b
:fire: remove repo template files
gimlichael 856dbca
:sparkles: add extensibility layer for benchmarkdotnet
gimlichael 69ad4fe
:test_tube: add comprehensive tests for BenchmarkWorkspaceOptions
gimlichael e7ec032
:rocket: add dedicated benchmarking suite and runner projects
gimlichael 6aeb59e
:chart_with_upwards_trend: add benchmarkdotnet github reports for wor…
gimlichael a65dcce
:lock: refactor assembly resolution for thread safety and speed
gimlichael ed120db
:memo: update ai docs for this repository
gimlichael 54e3de1
:rocket: add console integration for project
gimlichael bda283c
:heavy_plus_sign: add solution file for project organization
gimlichael 5d35470
:recycle: update branding, frameworks, and benchmark build settings
gimlichael a1cf015
:wastebasket: remove release notes file prop, add clean for benchmark…
gimlichael a3a0628
:arrow_up: bump dependencies
gimlichael 42167d2
:sparkles: add benchmark suite for core classes and operations
gimlichael e37b15d
:recycle: migrate to .slnx format
gimlichael 7eaaa7f
:arrow_up: bump dependencies
gimlichael f8815ad
:memo: update benchmark naming and placement guidelines
gimlichael 3d430f7
:construction_worker: update ci pipeline for BenchmarkDotNet
gimlichael bccb3d4
:fire: remove template release notes, readme, and icon from project
gimlichael f9940f5
:bookmark: update changelog for initial stable release of packages
gimlichael 18608ce
:bookmark: add package release notes for BenchmarkDotNet extensions
gimlichael d9b5d20
✨ update type parameter in AddBenchmarkWorkspace method for clarity
gimlichael c524199
:art: add new icon.png image to project
gimlichael 469effd
✨ update docfx to match benchmarkdotnet
gimlichael 9e9288a
:package: updated NuGet package definition
gimlichael e69f60c
:art: add property group with description and tags to csproj files
gimlichael 4254e60
:art: update exception documentation for ConfigureBenchmarkDotNet method
gimlichael 9300d7d
:art: update readme to reflect benchmarkdotnet extensions
gimlichael 91a2c47
:chart_with_upwards_trend: add benchmark reports
gimlichael f889f3f
:art: update readme with folder structure and usage examples
gimlichael 4788207
:art: fix os matrix formatting in ci pipeline configuration
gimlichael 0af72cd
:pencil2: fix typo in benchmarkdotnet project/repo names in ci-pipeline
gimlichael d89b6b1
:adhesive_bandage: handle null GetEntryAssembly in BenchmarkProgram ctor
gimlichael File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| --- | ||
| mode: agent | ||
| description: 'Writing Performance Benchmarks in Codebelt.Extensions.BenchmarkDotNet' | ||
| --- | ||
|
|
||
| # Benchmark Fixture Prompt (Codebelt.Extensions.BenchmarkDotNet Tuning Benchmarks) | ||
|
|
||
| This prompt defines how to generate performance tests (“benchmarks”) for the Codebelt.Extensions.BenchmarkDotNet codebase using BenchmarkDotNet. | ||
| Benchmarks in Codebelt.Extensions.BenchmarkDotNet are *not* unit tests — they are micro- or component-level performance measurements that belong under the `tuning/` directory and follow strict conventions. | ||
|
|
||
| Copilot must follow these guidelines when generating benchmark fixtures. | ||
|
|
||
| --- | ||
|
|
||
| ## 1. Naming and Placement | ||
|
|
||
| - All benchmark projects live under the `tuning/` folder. | ||
| Examples: | ||
| - `tuning/Codebelt.Extensions.BenchmarkDotNet.Benchmarks/` | ||
| - `tuning/Codebelt.Extensions.BenchmarkDotNet.Console.Benchmarks/` | ||
|
|
||
| - **Namespaces must NOT end with `.Benchmarks`.** | ||
| They must mirror the production assembly’s namespace. | ||
|
|
||
| Example: | ||
| If benchmarking a type inside `Codebelt.Extensions.BenchmarkDotNet.Console`, then: | ||
|
|
||
| ```csharp | ||
| namespace Codebelt.Extensions.BenchmarkDotNet.Console | ||
| { | ||
| public class Sha512256Benchmark { … } | ||
| } | ||
| ``` | ||
|
|
||
| * **Benchmark class names must end with `Benchmark`.** | ||
| Example: `DateSpanBenchmark`, `FowlerNollVoBenchmark`. | ||
|
|
||
| * Benchmark files should be located in the matching benchmark project | ||
| (e.g., benchmarks for `Codebelt.Extensions.BenchmarkDotNet.Console` go in `Codebelt.Extensions.BenchmarkDotNet.Console.Benchmarks.csproj`). | ||
|
|
||
| * In the `.csproj` for each benchmark project, set the root namespace to the production namespace: | ||
|
|
||
| ```xml | ||
| <RootNamespace>Codebelt.Extensions.BenchmarkDotNet.Console</RootNamespace> | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 2. Attributes and Configuration | ||
|
|
||
| Each benchmark class should use: | ||
|
|
||
| ```csharp | ||
| [MemoryDiagnoser] | ||
| [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] | ||
| ``` | ||
|
|
||
| Optional but strongly recommended where meaningful: | ||
|
|
||
| * `[Params(...)]` — define small, medium, large input sizes. | ||
| * `[GlobalSetup]` — deterministic initialization of benchmark data. | ||
| * `[Benchmark(Description = "...")]` — always add descriptions. | ||
| * `[Benchmark(Baseline = true)]` — when comparing two implementations. | ||
|
|
||
| Avoid complex global configs; prefer explicit attributes inside the class. | ||
|
|
||
| --- | ||
|
|
||
| ## 3. Structure and Best Practices | ||
|
|
||
| A benchmark fixture must: | ||
|
|
||
| * Measure a **single logical operation** per benchmark method. | ||
| * Avoid I/O, networking, disk access, logging, or side effects. | ||
| * Avoid expensive setup inside `[Benchmark]` methods. | ||
| * Use deterministic data (e.g., seeded RNG or predefined constants). | ||
| * Use `[GlobalSetup]` to allocate buffers, random payloads, or reusable test data only once. | ||
| * Avoid shared mutable state unless reset per iteration. | ||
|
|
||
| Use representative input sizes such as: | ||
|
|
||
| ```csharp | ||
| [Params(8, 256, 4096)] | ||
| public int Count { get; set; } | ||
| ``` | ||
|
|
||
| BenchmarkDotNet will run each benchmark for each parameter value. | ||
|
|
||
| --- | ||
|
|
||
| ## 4. Method Naming Conventions | ||
|
|
||
| Use descriptive names that communicate intent: | ||
|
|
||
| * `Parse_Short` | ||
| * `Parse_Long` | ||
| * `ComputeHash_Small` | ||
| * `ComputeHash_Large` | ||
| * `Serialize_Optimized` | ||
| * `Serialize_Baseline` | ||
|
|
||
| When comparing approaches, always list them clearly and tag one as the baseline. | ||
|
|
||
| --- | ||
|
|
||
| ## 5. Example Benchmark Fixture | ||
|
|
||
| ```csharp | ||
| using BenchmarkDotNet.Attributes; | ||
| using BenchmarkDotNet.Configs; | ||
|
|
||
| namespace Codebelt.Extensions.BenchmarkDotNet | ||
| { | ||
| [MemoryDiagnoser] | ||
| [GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] | ||
| public class SampleOperationBenchmark | ||
| { | ||
| [Params(8, 256, 4096)] | ||
| public int Count { get; set; } | ||
|
|
||
| private byte[] _payload; | ||
|
|
||
| [GlobalSetup] | ||
| public void Setup() | ||
| { | ||
| _payload = new byte[Count]; | ||
| // deterministic initialization | ||
| } | ||
|
|
||
| [Benchmark(Baseline = true, Description = "Operation - baseline")] | ||
| public int Operation_Baseline() => SampleOperation.Process(_payload); | ||
|
|
||
| [Benchmark(Description = "Operation - optimized")] | ||
| public int Operation_Optimized() => SampleOperation.ProcessOptimized(_payload); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 6. Reporting and CI | ||
|
|
||
| * Benchmark projects live exclusively under `tuning/`. They must not affect production builds. | ||
| * Heavy BenchmarkDotNet runs should *not* run in CI unless explicitly configured. | ||
| * Reports are produced by the Codebelt.Extensions.BenchmarkDotNet benchmark runner and stored under its configured artifacts directory. | ||
|
|
||
| --- | ||
|
|
||
| ## 7. Additional Guidelines | ||
|
|
||
| * Keep benchmark fixtures focused and readable. | ||
| * Document non-obvious reasoning in short comments. | ||
| * Prefer realistic but deterministic data sets. | ||
| * When benchmarks reveal regressions or improvements, reference the associated PR or issue in a comment. | ||
| * Shared benchmark helpers belong in `tuning/` projects, not in production code. | ||
|
|
||
| --- | ||
|
|
||
| ## Final Notes | ||
|
|
||
| * Benchmarks are performance tests, not unit tests. | ||
| * Use `[Benchmark]` only for pure performance measurement. | ||
| * Avoid `MethodImplOptions.NoInlining` unless absolutely necessary. | ||
| * Use small sets of meaningful benchmark scenarios — avoid combinatorial explosion. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix YAML newline style (CRLF vs LF) to satisfy yamllint. The lint error suggests the file is committed with
\r\n; normalize to\nto avoid CI noise.🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 1-1: wrong new line character: expected \n
(new-lines)
🤖 Prompt for AI Agents