This project contains performance benchmarks comparing reflection-based test execution with the new reflection-free delegate-based approach.
- Compares reflection-based test discovery vs pre-compiled metadata
- Measures filtering performance
- Tests category-based discovery
- Synchronous test execution
- Asynchronous test execution
- Parameterized test execution
- Test instance creation
- Full test lifecycle with hooks
- Property data source access
- Method data source invocation
- Async data source handling
- Complex data expansion
- Tuple conversion performance
cd TUnit.Performance.Tests
dotnet run -c Release# Build for AOT
dotnet publish -c Release -r win-x64 --self-contained -p:PublishAot=true
# Run the published executable
./bin/Release/net8.0/win-x64/publish/TUnit.Performance.Tests.exe# Run only discovery benchmarks
dotnet run -c Release -- --filter *Discovery*
# Run only execution benchmarks
dotnet run -c Release -- --filter *Execution*
# Run only data source benchmarks
dotnet run -c Release -- --filter *DataSource*- Delegate-based discovery should be 10-50x faster than reflection
- No allocations for pre-compiled metadata enumeration
- Constant time complexity for delegate lookup
- Delegate invocation ~5-10x faster than reflection
- Significant reduction in allocations
- Better performance scaling with parameter count
- Property access via delegates ~20x faster
- Method invocation ~10x faster
- Async overhead reduced by ~50%
The benchmarks will output:
- Mean: Average execution time
- Error: Half of 99.9% confidence interval
- StdDev: Standard deviation of all measurements
- Gen0/1/2: Number of garbage collections
- Allocated: Memory allocated per operation
Lower numbers are better for all metrics.
When running with Native AOT:
- Startup time reduced by 60-80%
- Memory footprint reduced by 40-60%
- Consistent performance (no JIT warmup)
- Smaller deployment size
- Baseline is always the reflection-based approach
- Benchmarks use BenchmarkDotNet for accuracy
- Results vary based on hardware and .NET version
- AOT benchmarks require .NET 8.0 or later