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_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_bench.zig')
| -rw-r--r-- | test/pdf_bench.zig | 49 |
1 files changed, 20 insertions, 29 deletions
diff --git a/test/pdf_bench.zig b/test/pdf_bench.zig index 0f09f72a..9054698b 100644 --- a/test/pdf_bench.zig +++ b/test/pdf_bench.zig @@ -9,10 +9,13 @@ //! ReleaseFast. Timed regions include MuPDF rasterization directly into the //! allocator-owned RGBA output; tint scenarios additionally include the exact //! in-place PDF transform used by the core. Checksum/free/reporting stay -//! outside. "cold" means a fresh Document and MuPDF page cache (the OS -//! filesystem cache is deliberately uncontrolled), while warm scenarios -//! retain one Document. +//! outside. "cold" means a fresh Document and MuPDF page cache, opened from +//! the file's bytes (read once, untimed, as the view reads a file whole), +//! while warm scenarios retain one Document. const std = @import("std"); +const bench_util = @import("bench_util.zig"); +const nowNs = bench_util.nowNs; +const fatal = bench_util.Fatal("pdf-bench").f; const pdf = @import("mupdf"); pub const std_options: std.Options = .{ .log_level = .err }; @@ -25,6 +28,8 @@ const checksum_seed: u64 = 0x7061_7264_6573_5044; const Config = struct { path: []const u8 = "docs/design.pdf", + /// the file at `path`, read whole before anything is timed + bytes: []const u8 = "", page: usize = 0, reps: usize = default_reps, warmup: usize = default_warmup, @@ -137,9 +142,11 @@ const Result = struct { pub fn main(init: std.process.Init) !void { const args = try init.minimal.args.toSlice(init.arena.allocator()); - const config = parseArgs(args); + var config = parseArgs(args); + config.bytes = std.Io.Dir.cwd().readFileAlloc(init.io, config.path, gpa, .unlimited) catch |err| + fatal("cannot read {s}: {t}", .{ config.path, err }); - var probe = pdf.Document.open(config.path) catch |err| + var probe = pdf.Document.openBytes(config.bytes) catch |err| fatal("cannot open {s}: {t}", .{ config.path, err }); const document_pages = probe.pages; probe.deinit(); @@ -205,14 +212,6 @@ fn parseArgs(args: []const []const u8) Config { return config; } -fn parsePositive(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; -} - fn usage() noreturn { printUsage(); std.process.exit(2); @@ -226,13 +225,6 @@ fn printUsage() void { ); } -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)); -} - fn measure( config: Config, profile_index: usize, @@ -251,7 +243,7 @@ fn measure( if (scenario.lifecycle == .cold_document_page) { for (0..rounds) |round| { const timed = try timeCold( - config.path, + config.bytes, config.page, profile.request, scenario.decoration, @@ -265,7 +257,7 @@ fn measure( } } } else { - var document = try pdf.Document.open(config.path); + var document = try pdf.Document.openBytes(config.bytes); defer document.deinit(); for (0..rounds) |round| { const timed = switch (scenario.lifecycle) { @@ -310,14 +302,14 @@ fn measure( } fn timeCold( - path: []const u8, + bytes: []const u8, page: usize, request: pdf.RenderRequest, decoration: Decoration, tint: pdf.TintMode, ) !Timed { const started = nowNs(); - var document = try pdf.Document.open(path); + var document = try pdf.Document.openBytes(bytes); errdefer document.deinit(); const rendered = try renderPage(&document, page, request, decoration, tint); const elapsed = @max(@as(u64, 1), nowNs() -| started); @@ -376,8 +368,8 @@ fn renderPage( tint: pdf.TintMode, ) !pdf.Render { const rendered = switch (decoration) { - .plain => document.renderAt(gpa, page, request), - .highlighted => document.renderWithHighlightsAt(gpa, page, request, &highlights), + .plain => document.render(gpa, page, request, &.{}), + .highlighted => document.render(gpa, page, request, &highlights), }; const fresh = try rendered; errdefer gpa.free(fresh.rgba); @@ -617,7 +609,6 @@ fn reportJson( std.Io.File.stdout().writeStreamingAll(io, out.buffered()) catch {}; } -fn fatal(comptime format: []const u8, args: anytype) noreturn { - std.debug.print("pdf-bench: " ++ format ++ "\n", args); - std.process.exit(1); +fn parsePositive(name: []const u8, text: []const u8, maximum: usize) usize { + return bench_util.parsePositive(fatal, name, text, maximum); } |
