diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-30 17:35:06 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-30 17:35:06 -0300 |
| commit | 6d8da8721141284cf33bb901168b26135893eb86 (patch) | |
| tree | 791d63401d4e85fbca1d597a8ce0326e70efd545 /test/pdf_sections_bench.zig | |
| parent | efd43a3a2cf03bb741366331158b368abf9ac583 (diff) | |
| parent | bf6810a8f9d6cc82050e7d9c0cfb06358301b574 (diff) | |
| download | pardes-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/pdf_sections_bench.zig')
| -rw-r--r-- | test/pdf_sections_bench.zig | 75 |
1 files changed, 25 insertions, 50 deletions
diff --git a/test/pdf_sections_bench.zig b/test/pdf_sections_bench.zig index b08af552..ce548924 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"); @@ -67,7 +72,7 @@ pub fn main(init: std.process.Init) !void { try writeFile(path, fixture); defer unlink(path); - var document = try pdf.Document.open(path); + var document = try pdf.Document.openBytes(fixture); defer document.deinit(); var outline = try document.outline(gpa); defer outline.deinit(gpa); @@ -76,7 +81,7 @@ pub fn main(init: std.process.Init) !void { defer gpa.free(synthetic); const results = [_]Result{ - try measureOutline(path, config), + try measureOutline(fixture, config), try measureMaterialize(path, outline.entries, config), try measureCachedControl(path, config), try measureCachedReopen(path, config), @@ -107,22 +112,14 @@ 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 { +fn measureOutline(fixture: []const u8, config: Config) !Result { const samples = try gpa.alloc(u64, config.reps); defer gpa.free(samples); var expected: ?Identity = null; for (0..config.warmup + config.reps) |round| { // Document open/close is setup: this row isolates MuPDF outline load, // bridge flattening, and the Zig-owned two-allocation copy. - var document = try pdf.Document.open(path); + var document = try pdf.Document.openBytes(fixture); defer document.deinit(); const started = nowNs(); var outline = try document.outline(gpa); @@ -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 @@ -478,7 +454,7 @@ fn reportText(config: Config, results: []const Result) void { std.debug.print("{s:<42} {s:>10} {s:>10} {s:>10} {s:>10} {s:>8} {s:>8} {s}\n", .{ "scenario", "min", "median", "p90", "max", "items", "bytes", "checksum", }); - std.debug.print("{s}\n", .{"-" ** 124}); + std.debug.print("{s}\n", .{&@as([124]u8, @splat('-'))}); for (results) |result| std.debug.print( "{s:<42} {d:>10} {d:>10} {d:>10} {d:>10} {d:>8} {d:>8} {x:0>16}\n", .{ @@ -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); } |
