Performance benchmarks for Bitbucket.Net using BenchmarkDotNet.
- .NET 10.0 SDK or later
- Build the solution in Release mode for accurate results
cd benchmarks/Bitbucket.Net.Benchmarks
dotnet run -c ReleaseSelect option 1 from the menu to run all benchmarks.
dotnet run -c ReleaseThen select from the menu:
2- JSON Serialization benchmarks3- Streaming benchmarks4- Response Handling benchmarks
You can also run specific benchmarks directly:
# Run JSON serialization benchmarks only
dotnet run -c Release -- --filter "*JsonSerialization*"
# Run streaming benchmarks only
dotnet run -c Release -- --filter "*Streaming*"
# Run response handling benchmarks only
dotnet run -c Release -- --filter "*ResponseHandling*"Measures System.Text.Json performance for common operations:
DeserializeRepository- Deserialize a single repository with nested objectsDeserializePagedResults- Deserialize paged API responsesSerializeRepository- Serialize a repository objectSerializeProject- Serialize a project object
Compares IAsyncEnumerable streaming vs traditional buffered approaches:
StreamingEnumeration- Process items usingyield return(streaming)BufferedEnumeration- Process items by collecting to a List first (buffered)
Tests memory efficiency improvements from Issue #2 (IAsyncEnumerable Streaming).
Tests handling of various response sizes:
SmallResponse- ~1KB responseMediumResponse- ~100KB responseLargeResponse- ~1MB response
Measures allocation patterns and throughput for different payload sizes.
BenchmarkDotNet produces detailed reports including:
| Column | Description |
|---|---|
| Mean | Average execution time |
| Error | 99.9% confidence interval |
| StdDev | Standard deviation |
| Ratio | Relative performance compared to baseline |
| Allocated | Memory allocated per operation |
Results are exported to:
BenchmarkDotNet.Artifacts/results/(CSV, HTML, Markdown)
- Always use Release mode - Debug builds include debugging overhead
- Close other applications - Reduce system noise for consistent results
- Run multiple iterations - BenchmarkDotNet handles this automatically
- Compare against baseline - Use
[Benchmark(Baseline = true)]for comparisons
- Create a new class in the appropriate category folder
- Add
[MemoryDiagnoser]attribute for memory measurements - Use
[Config(typeof(BenchmarkConfig))]for consistent configuration - Add
[Benchmark]attribute to benchmark methods - Update
Program.csto include the new benchmark class
Example:
[MemoryDiagnoser]
[Config(typeof(BenchmarkConfig))]
public class MyNewBenchmarks
{
[GlobalSetup]
public void Setup()
{
// Initialize test data
}
[Benchmark(Baseline = true)]
public void BaselineMethod()
{
// Baseline implementation
}
[Benchmark]
public void ImprovedMethod()
{
// Implementation to compare
}
}For CI/CD pipelines, run benchmarks without the interactive menu:
dotnet run -c Release -- --filter "*" --exporters csv html markdownResults can be archived as build artifacts for trend analysis.