Skip to content

Add binary scaling and expand benchmarks (v0.0.3) - #4

Merged
mwsis merged 8 commits into
synesissoftware:masterfrom
mwsis:v3
Aug 1, 2026
Merged

mwsis merged 8 commits into
synesissoftware:masterfrom
mwsis:v3

Conversation

@mwsis

@mwsis mwsis commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Implement the optional $2^{32}$ fixed-point binary scaling float-avoidance optimizations from p99.Rust as a comptime build option (-Dbinary-scaling). Update all integer-based percentile query methods (valueAtP90, valueAtP95, valueAtP99, etc.) to use pre-encoded multipliers when binary_scaling is enabled, avoiding integer division
entirely.

Expand and harden the benchmark suite in benches/benchmark_histogram.zig to make it statistically robust and compiler-safe:

  • Add a benchmark for the clear() method;
  • Add a benchmark for the generic valueAtPercentile(f64) method;
  • Extend the random event range to match Rust's 10-second wide-range workload ([1, 10_000_000_000] nanoseconds);
  • Apply strict std.mem.doNotOptimizeAway constraints on inputs and the histogram inside loops to prevent compiler dead-code elimination and loop-invariant hoisting.

Bump the package version to 0.0.3 in build.zig.zon. Update CHANGES.md, NEWS.md, and TODO.md to document the release and check off the optimization task. Update README.md to add dedicated "Build Options" and "Benchmarks" sections with clear usage instructions.

mwsis added 6 commits July 26, 2026 09:35
Implement the core 64-bucket logarithmic performance percentile histogram
(`Histogram`) for Step 1. This includes branchless bucket indexing via CPU
`@clz` (count leading zeros) and linear interpolation for percentile
approximation.

Add a comprehensive unit test suite covering bucket index/range
calculations, event pushing, overflow handling, and percentile
interpolation. Add a benchmark suite using the modern Zig 0.16.0
`std.Io.Clock` API to measure raw CPU execution times, along with a minimal
usage example.

Refactor all executable outputs to use standard buffered `stdout` writers
instead of `std.debug.print` (which writes to `stderr`). Update `README.md`
with idiomatic `zig fetch` installation instructions, project metadata, and
a list of related `p99` ports. Document upcoming tasks in `TODO.md` and
bump the package version to `0.0.1` in `build.zig.zon`.
Add a GitHub Actions CI workflow (`.github/workflows/ci.yml`) to
automatically run formatting checks, library unit tests, example runs, and
benchmark suites across Linux (Ubuntu), macOS, and Windows.

Bump the package version to `0.0.2` in `build.zig.zon`. Update `CHANGES.md`,
`NEWS.md`, and `TODO.md` to document the release and mark the CI setup task
as completed.
Implement the optional $2^{32}$ fixed-point binary scaling
float-avoidance optimizations from `p99.Rust` as a comptime build option
(`-Dbinary-scaling`). Update all integer-based percentile query methods
(`valueAtP90`, `valueAtP95`, `valueAtP99`, etc.) to use pre-encoded
multipliers when `binary_scaling` is enabled, avoiding integer division
entirely.

Expand and harden the benchmark suite in `benches/benchmark_histogram.zig`
to make it statistically robust and compiler-safe:
* Add a benchmark for the `clear()` method;
* Add a benchmark for the generic `valueAtPercentile(f64)` method;
* Extend the random event range to match Rust's 10-second wide-range
  workload (`[1, 10_000_000_000]` nanoseconds);
* Apply strict `std.mem.doNotOptimizeAway` constraints on inputs and the
  histogram inside loops to prevent compiler dead-code elimination and
  loop-invariant hoisting.

Bump the package version to `0.0.3` in `build.zig.zon`. Update `CHANGES.md`,
`NEWS.md`, and `TODO.md` to document the release and check off the
optimization task. Update `README.md` to add dedicated "Build Options" and
"Benchmarks" sections with clear usage instructions.
@mwsis
mwsis requested a review from synesissoftware July 26, 2026 03:02
@mwsis mwsis self-assigned this Jul 26, 2026
@mwsis
mwsis merged commit 95027f8 into synesissoftware:master Aug 1, 2026
4 checks passed
@mwsis
mwsis deleted the v3 branch August 1, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants