Add binary scaling and expand benchmarks (v0.0.3) - #4
Merged
Merged
Conversation
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.
synesissoftware
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement the optional$2^{32}$ fixed-point binary scaling float-avoidance optimizations from
p99.Rustas a comptime build option (-Dbinary-scaling). Update all integer-based percentile query methods (valueAtP90,valueAtP95,valueAtP99, etc.) to use pre-encoded multipliers whenbinary_scalingis enabled, avoiding integer divisionentirely.
Expand and harden the benchmark suite in
benches/benchmark_histogram.zigto make it statistically robust and compiler-safe:clear()method;valueAtPercentile(f64)method;[1, 10_000_000_000]nanoseconds);std.mem.doNotOptimizeAwayconstraints on inputs and the histogram inside loops to prevent compiler dead-code elimination and loop-invariant hoisting.Bump the package version to
0.0.3inbuild.zig.zon. UpdateCHANGES.md,NEWS.md, andTODO.mdto document the release and check off the optimization task. UpdateREADME.mdto add dedicated "Build Options" and "Benchmarks" sections with clear usage instructions.