abbasmhd / abbasmhd/CifraId

Add BenchmarkDotNet project for performance measurement

Open
#3 0 comments 0 reactions 1 assignee Claimed by @abbasmhd View on GitHub
enhancement
Dominant language
C#
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Summary

Add a dedicated benchmark project to measure encoding/decoding and service-layer performance for CifraId. This gives contributors a repeatable way to compare the Hashids-based encoder against the NoOp pass-through implementations and to catch regressions when optimizing hot paths.

## Motivation

CifraId runs on every API request that serializes or binds `[CifraId]` properties. Understanding throughput and allocation cost for encode/decode operations helps guide optimization work and documents expected performance characteristics for integrators.

## Proposed structure

```
benchmarks/
CifraId.Benchmarks/
CifraId.Benchmarks.csproj
Program.cs
EncoderBenchmarks.cs
ServiceBenchmarks.cs
```

- Add the project under a `benchmarks/` solution folder in `CifraId.slnx`
- Target `net10.0` (consistent with the rest of the solution)
- Reference `CifraId.Core` only (benchmarks should not require ASP.NET Core hosting)
- Use [BenchmarkDotNet](https://benchmarkdotnet.org/) with `[MemoryDiagnoser]` for allocation reporting

## Benchmark coverage

### Encoder benchmarks

Compare `Encoder` (Hashids-style reversible encoding) vs `NoOpEncoder`:

- `Encode` across representative ID values (small, large, near `int.MaxValue`)
- `Decode` for small and large encoded strings

### Service benchmarks

Compare `CifraIdService` vs `NoOpCifraIdService`:

- Single ID encode/decode
- Batch `EncodeIds` / `DecodeIds`
- Enum encode/decode

Each benchmark suite should establish a baseline so relative differences are easy to read in reports.

## How to run

```shell
dotnet run --project benchmarks/CifraId.Benchmarks -c Release
```

Run specific benchmark types by passing the BenchmarkDotNet filter argument, for example:

```shell
dotnet run --project benchmarks/CifraId.Benchmarks -c Release -- --filter *EncoderBenchmarks*
```

## Acceptance criteria

- [ ] `benchmarks/CifraId.Benchmarks` project builds in Release configuration
- [ ] Project is included in `CifraId.slnx` under a `benchmarks/` folder
- [ ] Encoder and service encode/decode paths are covered, including NoOp variants
- [ ] README or CONTRIBUTING documents how to run benchmarks locally
- [ ] Benchmark project is excluded from NuGet packaging and CI test runs (optional: add a manual or scheduled CI workflow later)

## Notes

- Benchmarks are for local development and regression tracking; they do not replace unit/integration tests
- Use a fixed salt and `HashSettings` in `[GlobalSetup]` so results are reproducible across runs on the same machine
- Release configuration is required for meaningful BenchmarkDotNet results

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.