summaryrefslogtreecommitdiff
path: root/test/pdf_bench.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-23 10:51:51 -0300
committerGabriel Schneider <[email protected]>2026-10-23 17:10:58 -0300
commit7b743fcc7d568f13512a59089c5214bb6fa3282f (patch)
treeab133f70ded7b9b415115345adfc6ff043117b03 /test/pdf_bench.zig
parentb8f076b63d6fcbb01539d5541520a32bccc0e219 (diff)
downloadpardes-7b743fcc7d568f13512a59089c5214bb6fa3282f.tar.gz
pardes-7b743fcc7d568f13512a59089c5214bb6fa3282f.zip
Audit (LSP, PDF): one client dispatch, docParams, renameEdits in one loop, std.c externs; one whole-page render, openBytes only
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test/pdf_bench.zig')
-rw-r--r--test/pdf_bench.zig26
1 files changed, 15 insertions, 11 deletions
diff --git a/test/pdf_bench.zig b/test/pdf_bench.zig
index 23565106..9054698b 100644
--- a/test/pdf_bench.zig
+++ b/test/pdf_bench.zig
@@ -9,9 +9,9 @@
//! 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;
@@ -28,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,
@@ -140,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();
@@ -239,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,
@@ -253,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) {
@@ -298,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);
@@ -364,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);