summaryrefslogtreecommitdiff
path: root/test/bench_util.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
committerGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
commit6d8da8721141284cf33bb901168b26135893eb86 (patch)
tree791d63401d4e85fbca1d597a8ce0326e70efd545 /test/bench_util.zig
parentefd43a3a2cf03bb741366331158b368abf9ac583 (diff)
parentbf6810a8f9d6cc82050e7d9c0cfb06358301b574 (diff)
downloadpardes-6d8da8721141284cf33bb901168b26135893eb86.tar.gz
pardes-6d8da8721141284cf33bb901168b26135893eb86.zip
Merge latest upstream into the macOS branch for Zig 0.17
Retain the macOS branch history and local Acme selection color while adopting upstream's current core and platform changes. Pin Zig and ZLS to 0.17.0, and fetch the existing zstbi compatibility commit through upstream after its original fork was removed.
Diffstat (limited to 'test/bench_util.zig')
-rw-r--r--test/bench_util.zig43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/bench_util.zig b/test/bench_util.zig
new file mode 100644
index 00000000..9b91e621
--- /dev/null
+++ b/test/bench_util.zig
@@ -0,0 +1,43 @@
+//! What the PDF benches share: a clock, a fatal exit named for the bench, a
+//! seeded hash, a count parser and the core's effect drain.
+const std = @import("std");
+
+pub fn nowNs() u64 {
+ var ts: std.c.timespec = undefined;
+ _ = std.c.clock_gettime(.MONOTONIC, &ts);
+ return @as(u64, @intCast(ts.sec)) *| 1_000_000_000 +| @as(u64, @intCast(ts.nsec));
+}
+
+/// `fatal` for the bench called `who`: says so, prefixed, and exits 1.
+pub fn Fatal(comptime who: []const u8) type {
+ return struct {
+ pub fn f(comptime format: []const u8, args: anytype) noreturn {
+ std.debug.print(who ++ ": " ++ format ++ "\n", args);
+ std.process.exit(1);
+ }
+ };
+}
+
+/// A seeded hash of `value`'s bytes; a comptime integer hashes as a u64.
+pub fn mix(seed: u64, value: anytype) u64 {
+ const Value = @TypeOf(value);
+ const Stable = switch (@typeInfo(Value)) {
+ .comptime_int => u64,
+ else => Value,
+ };
+ var stable: Stable = value;
+ return std.hash.Wyhash.hash(seed, std.mem.asBytes(&stable));
+}
+
+/// A flag's value as a count in 1..`maximum`, or `fatal` saying why not.
+pub fn parsePositive(comptime fatal: anytype, name: []const u8, text: []const u8, maximum: usize) usize {
+ const value = std.fmt.parseUnsigned(usize, text, 10) catch
+ fatal("{s} expects a positive integer", .{name});
+ if (value == 0 or value > maximum)
+ fatal("{s} must be in 1..{d}", .{ name, maximum });
+ return value;
+}
+
+pub fn drainEffects(core: anytype) void {
+ while (core.nextEffect()) |_| {}
+}