summaryrefslogtreecommitdiff
path: root/test/pdf_sections_bench.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/pdf_sections_bench.zig')
-rw-r--r--test/pdf_sections_bench.zig65
1 files changed, 20 insertions, 45 deletions
diff --git a/test/pdf_sections_bench.zig b/test/pdf_sections_bench.zig
index b08af552..92c9ef7c 100644
--- a/test/pdf_sections_bench.zig
+++ b/test/pdf_sections_bench.zig
@@ -9,6 +9,11 @@
//! report nanoseconds per operation; `operations_per_sample` makes that
//! normalization explicit in both output formats.
const std = @import("std");
+const bench_util = @import("bench_util.zig");
+const nowNs = bench_util.nowNs;
+const fatal = bench_util.Fatal("pdf-sections-bench").f;
+const mix = bench_util.mix;
+const drainEffects = bench_util.drainEffects;
const libc = std.c;
const pardes = @import("pardes");
const pdf = @import("mupdf");
@@ -107,14 +112,6 @@ fn parseArgs(args: []const []const u8) Config {
return config;
}
-fn parseCount(flag: []const u8, text: []const u8) usize {
- const value = std.fmt.parseUnsigned(usize, text, 10) catch
- fatal("{s} expects a positive integer", .{flag});
- if (value == 0 or value > 10_000)
- fatal("{s} must be in 1..10000", .{flag});
- return value;
-}
-
fn measureOutline(path: []const u8, config: Config) !Result {
const samples = try gpa.alloc(u64, config.reps);
defer gpa.free(samples);
@@ -145,7 +142,7 @@ fn measureMaterialize(
var expected: ?Identity = null;
for (0..config.warmup + config.reps) |round| {
const started = nowNs();
- const content = try pardes.PdfSectionRows.render(gpa, path, entries);
+ const content = try pardes.panes.Pdf.SectionRows.render(gpa, path, entries);
const elapsed = nowNs() -| started;
const identity = contentIdentity(content);
gpa.free(content);
@@ -255,7 +252,7 @@ fn measureWorstShape(entries: []const pdf.OutlineEntry, config: Config) !Result
var expected: ?Identity = null;
for (0..config.warmup + config.reps) |round| {
const started = nowNs();
- const content = try pardes.PdfSectionRows.render(gpa, "/tmp/near-limit.pdf", entries);
+ const content = try pardes.panes.Pdf.SectionRows.render(gpa, "/tmp/near-limit.pdf", entries);
const elapsed = nowNs() -| started;
const identity = contentIdentity(content);
gpa.free(content);
@@ -300,11 +297,11 @@ fn perturbReopen(prepared: PreparedReopen, operation: usize) void {
const marker: i32 = @intCast(operation % 31 + 1);
const output_file = &prepared.output.file.?;
output_file.scroll = @intCast(operation % 17 + 1);
- prepared.output.cur_row = marker;
- prepared.output.cur_col = marker + 1;
- prepared.output.msel.active = true;
- prepared.output.vsel.active = true;
- prepared.output.nsel = 1;
+ prepared.output.body.cur_row = marker;
+ prepared.output.body.cur_col = marker + 1;
+ prepared.output.body.msel.active = true;
+ prepared.output.body.vsel.active = true;
+ prepared.output.body.nsel = 1;
prepared.owner.search_pane = null;
prepared.owner.search_row = operation % 23;
prepared.core.active = prepared.output_id;
@@ -313,21 +310,17 @@ fn perturbReopen(prepared: PreparedReopen, operation: usize) void {
fn observeReopen(prepared: PreparedReopen) u64 {
const file = prepared.output.file.?;
var observed: u64 = file.scroll;
- observed = observed *% 131 +% @as(u64, @intCast(@max(0, prepared.output.cur_row)));
- observed = observed *% 131 +% @as(u64, @intCast(@max(0, prepared.output.cur_col)));
- observed = observed *% 131 +% @intFromBool(prepared.output.msel.active);
- observed = observed *% 131 +% @intFromBool(prepared.output.vsel.active);
- observed = observed *% 131 +% prepared.output.nsel;
+ observed = observed *% 131 +% @as(u64, @intCast(@max(0, prepared.output.body.cur_row)));
+ observed = observed *% 131 +% @as(u64, @intCast(@max(0, prepared.output.body.cur_col)));
+ observed = observed *% 131 +% @intFromBool(prepared.output.body.msel.active);
+ observed = observed *% 131 +% @intFromBool(prepared.output.body.vsel.active);
+ observed = observed *% 131 +% prepared.output.body.nsel;
observed = observed *% 131 +% (prepared.owner.search_pane orelse std.math.maxInt(usize));
observed = observed *% 131 +% (prepared.owner.search_row orelse std.math.maxInt(usize));
observed = observed *% 131 +% prepared.core.active;
return observed;
}
-fn drainEffects(core: *pardes.Pardes) void {
- while (core.nextEffect()) |_| {}
-}
-
fn sectionsOutputIdentity(core: *pardes.Pardes) Identity {
const owner = core.panes[0] orelse fatal("PDF pane disappeared", .{});
const output_id = owner.search_pane orelse fatal("+PdfSections was not armed", .{});
@@ -347,7 +340,7 @@ fn stepIdentity(core: *pardes.Pardes) Identity {
identity.checksum = mix(identity.checksum, view.page);
identity.checksum = mix(identity.checksum, @as(u64, @bitCast(view.document_scroll_y)));
identity.checksum = mix(identity.checksum, owner.search_row orelse std.math.maxInt(usize));
- identity.checksum = mix(identity.checksum, view.render_revision);
+ identity.checksum = mix(identity.checksum, view.next_raster_revision);
return identity;
}
@@ -389,16 +382,6 @@ fn outlineIdentity(entries: []const pdf.OutlineEntry) Identity {
return .{ .items = entries.len, .bytes = bytes, .checksum = checksum };
}
-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));
-}
-
fn makeWorstShape() ![]pdf.OutlineEntry {
const entries = try gpa.alloc(pdf.OutlineEntry, near_limit_items);
for (entries, 0..) |*entry, ordinal| {
@@ -457,13 +440,6 @@ fn summarize(
};
}
-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));
-}
-
/// A host benchmark compiler barrier. MuPDF benchmarks are build-and-run
/// steps, so they never target the freestanding web backend; an empty volatile
/// asm with only the abstract memory clobber is valid on every native backend
@@ -545,7 +521,6 @@ fn unlink(path: []const u8) void {
_ = libc.unlink(path_z);
}
-fn fatal(comptime format: []const u8, args: anytype) noreturn {
- std.debug.print("pdf-sections-bench: " ++ format ++ "\n", args);
- std.process.exit(1);
+fn parseCount(flag: []const u8, text: []const u8) usize {
+ return bench_util.parsePositive(fatal, flag, text, 10_000);
}