basic arithmetic benchmarks added
.NET Test / .NET tests (push) Successful in 1m9s

This commit is contained in:
2026-09-14 00:04:39 +04:00
parent e05e1e902a
commit cb2524980d
6 changed files with 186 additions and 9 deletions
+39 -4
View File
@@ -42,7 +42,7 @@ rounded 106-bit results**. The deterministic rational-oracle tests check a
conservative error bound of `2^-100` relative plus one minimum binary64 subnormal,
with exact component checks for selected representable cases. Near underflow,
extended precision necessarily decreases; overflow produces infinity. Performance
has not been benchmarked, including the allocating exponent-boundary path.
of the allocating exponent-boundary path is not covered by the basic benchmarks.
## Conversions and formatting
@@ -133,8 +133,8 @@ bool success = DoubleDouble.TryParse("1.25e-2".AsSpan(), CultureInfo.InvariantCu
The planned `PreciseMath` static class and its `Abs`, `Sqrt`, `Pow`, `Exp`, and
`Log` functions are not implemented. Generic-math interfaces beyond `ISignedNumber`,
additional text formats/general round-trip formatting, and performance benchmarks
remain deferred.
additional text formats/general round-trip formatting, and broader performance
benchmarks remain deferred.
Replacing allocating arithmetic boundary fallbacks is also deferred; the current
`BigInteger` paths remain in place. That optimization does not require removing
`BigInteger` from conversions, parsing, formatting, or independent test oracles.
@@ -154,11 +154,46 @@ dotnet format Just.PreciseMath.slnx --verify-no-changes --no-restore
Test results and coverage reports are available in the `test-results` artifact
on CI workflow runs.
## Benchmarks
The BenchmarkDotNet suite compares same-type `+`, `-`, `*`, and `/` operations for
`DoubleDouble`, `decimal`, and `double`: 12 methods with two input cases each.
Each operation/input group uses `double` as its baseline and reports allocations.
Operands are stored in fields and results are returned to the harness; conversions
and construction happen in setup, outside the timed methods.
The left inputs are `1.25` (binary-exact) and `1.1` (a nonzero low component in
`DoubleDouble`); the right input is `0.75`. Decimal and double-double inputs originate
from the same decimal values, while `double` rounds to binary64. These types have
different precision and range contracts: this is a cost comparison, not an accuracy
test. Exceptional values, exponent-boundary fallbacks, mixed-type operators,
conversions, parsing, and formatting are not benchmarked yet.
After the Release build above, run from the repository root:
```sh
# Discover benchmark methods without running them.
dotnet run --project 2-benchmarks/Just.PreciseMath.Benchmarks -c Release --no-build -- --list flat
# Quick execution check (also run in CI); not useful for timing comparisons.
dotnet run --project 2-benchmarks/Just.PreciseMath.Benchmarks -c Release --no-build -- --job Dry --filter '*'
# Full measurement run; optionally select an operation with --anyCategories Addition.
dotnet run --project 2-benchmarks/Just.PreciseMath.Benchmarks -c Release --no-build -- --filter '*'
```
Reports are written under the ignored `BenchmarkDotNet.Artifacts/` directory.
Empty selections and failed benchmark runs return a nonzero exit code. CI only
checks execution, with no performance gate. Use full runs on an idle, controlled
machine for comparisons; a scalar `double` operation may approach harness overhead,
so inspect BenchmarkDotNet warnings before interpreting ratios. Do not compare
coverage-instrumented runs or treat Dry-job timings as performance measurements.
## Project structure
- `0-source/Just.PreciseMath/`: library implementation.
- `1-tests/Just.PreciseMath.Tests/`: unit tests.
- `2-benchmarks/Just.PreciseMath.Benchmarks/`: reserved for performance benchmarks.
- `2-benchmarks/Just.PreciseMath.Benchmarks/`: arithmetic benchmarks against `decimal` and `double`.
## Contributing