summaryrefslogtreecommitdiff
path: root/test/pdf_sections_bench.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-08-09 10:41:33 -0300
committerGabriel Schneider <[email protected]>2026-08-10 09:17:07 -0300
commit9085cb5bfdd0b78ff3a62c0c71fc231dd7b5052a (patch)
tree91fce278abc85e4f7491de8b5f02184c8a2d5a56 /test/pdf_sections_bench.zig
parent2b1fac6fecbf7d7cc08f9dad24687b05e9968c9a (diff)
downloadpardes-9085cb5bfdd0b78ff3a62c0c71fc231dd7b5052a.tar.gz
pardes-9085cb5bfdd0b78ff3a62c0c71fc231dd7b5052a.zip
replace ArrayLists with bounded storage
Diffstat (limited to 'test/pdf_sections_bench.zig')
-rw-r--r--test/pdf_sections_bench.zig61
1 files changed, 31 insertions, 30 deletions
diff --git a/test/pdf_sections_bench.zig b/test/pdf_sections_bench.zig
index 21327c9f..9d44a3dd 100644
--- a/test/pdf_sections_bench.zig
+++ b/test/pdf_sections_bench.zig
@@ -116,8 +116,8 @@ fn parseCount(flag: []const u8, text: []const u8) usize {
}
fn measureOutline(path: []const u8, config: Config) !Result {
- var samples: std.ArrayList(u64) = .empty;
- defer samples.deinit(gpa);
+ 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,
@@ -130,9 +130,9 @@ fn measureOutline(path: []const u8, config: Config) !Result {
const identity = outlineIdentity(outline.entries);
outline.deinit(gpa);
try verifyIdentity("outline-load-flatten-real", &expected, identity, round);
- if (round >= config.warmup) try samples.append(gpa, @max(1, elapsed));
+ if (round >= config.warmup) samples[round - config.warmup] = @max(1, elapsed);
}
- return summarize("outline-load-flatten-real", 1, samples.items, expected.?);
+ return summarize("outline-load-flatten-real", 1, samples, expected.?);
}
fn measureMaterialize(
@@ -140,8 +140,8 @@ fn measureMaterialize(
entries: []const pdf.OutlineEntry,
config: Config,
) !Result {
- var samples: std.ArrayList(u64) = .empty;
- defer samples.deinit(gpa);
+ const samples = try gpa.alloc(u64, config.reps);
+ defer gpa.free(samples);
var expected: ?Identity = null;
for (0..config.warmup + config.reps) |round| {
const started = nowNs();
@@ -150,17 +150,17 @@ fn measureMaterialize(
const identity = contentIdentity(content);
gpa.free(content);
try verifyIdentity("sections-first-materialize", &expected, identity, round);
- if (round >= config.warmup) try samples.append(gpa, @max(1, elapsed));
+ if (round >= config.warmup) samples[round - config.warmup] = @max(1, elapsed);
}
- return summarize("sections-first-materialize", 1, samples.items, expected.?);
+ return summarize("sections-first-materialize", 1, samples, expected.?);
}
fn measureCachedReopen(path: []const u8, config: Config) !Result {
const core = try preparedCore(path);
defer core.deinit();
const prepared = preparedReopen(core);
- var samples: std.ArrayList(u64) = .empty;
- defer samples.deinit(gpa);
+ const samples = try gpa.alloc(u64, config.reps);
+ defer gpa.free(samples);
var expected: ?Identity = null;
for (0..config.warmup + config.reps) |round| {
var observed: u64 = 0;
@@ -182,9 +182,9 @@ fn measureCachedReopen(path: []const u8, config: Config) !Result {
identity.checksum = mix(identity.checksum, observed);
try verifyIdentity("sections-clean-cached-reopen", &expected, identity, round);
if (round >= config.warmup)
- try samples.append(gpa, @max(1, elapsed / cached_batch));
+ samples[round - config.warmup] = @max(1, elapsed / cached_batch);
}
- return summarize("sections-clean-cached-reopen", cached_batch, samples.items, expected.?);
+ return summarize("sections-clean-cached-reopen", cached_batch, samples, expected.?);
}
/// Cost floor for the anti-elision workload above. This performs the same
@@ -194,8 +194,8 @@ fn measureCachedControl(path: []const u8, config: Config) !Result {
const core = try preparedCore(path);
defer core.deinit();
const prepared = preparedReopen(core);
- var samples: std.ArrayList(u64) = .empty;
- defer samples.deinit(gpa);
+ const samples = try gpa.alloc(u64, config.reps);
+ defer gpa.free(samples);
var expected: ?Identity = null;
for (0..config.warmup + config.reps) |round| {
var observed: u64 = 0;
@@ -212,17 +212,17 @@ fn measureCachedControl(path: []const u8, config: Config) !Result {
identity.checksum = mix(identity.checksum, observed);
try verifyIdentity("sections-perturb-observe-control", &expected, identity, round);
if (round >= config.warmup)
- try samples.append(gpa, @max(1, elapsed / cached_batch));
+ samples[round - config.warmup] = @max(1, elapsed / cached_batch);
}
- return summarize("sections-perturb-observe-control", cached_batch, samples.items, expected.?);
+ return summarize("sections-perturb-observe-control", cached_batch, samples, expected.?);
}
fn measureOrdinalStep(path: []const u8, config: Config) !Result {
const core = try preparedCore(path);
defer core.deinit();
const owner = core.panes[0].?;
- var samples: std.ArrayList(u64) = .empty;
- defer samples.deinit(gpa);
+ const samples = try gpa.alloc(u64, config.reps);
+ defer gpa.free(samples);
var expected: ?Identity = null;
for (0..config.warmup + config.reps) |round| {
owner.search_row = null;
@@ -244,14 +244,14 @@ fn measureOrdinalStep(path: []const u8, config: Config) !Result {
const identity = stepIdentity(core);
try verifyIdentity("sections-ordinal-destination-step", &expected, identity, round);
if (round >= config.warmup)
- try samples.append(gpa, @max(1, elapsed / step_batch));
+ samples[round - config.warmup] = @max(1, elapsed / step_batch);
}
- return summarize("sections-ordinal-destination-step", step_batch, samples.items, expected.?);
+ return summarize("sections-ordinal-destination-step", step_batch, samples, expected.?);
}
fn measureWorstShape(entries: []const pdf.OutlineEntry, config: Config) !Result {
- var samples: std.ArrayList(u64) = .empty;
- defer samples.deinit(gpa);
+ const samples = try gpa.alloc(u64, config.reps);
+ defer gpa.free(samples);
var expected: ?Identity = null;
for (0..config.warmup + config.reps) |round| {
const started = nowNs();
@@ -260,9 +260,9 @@ fn measureWorstShape(entries: []const pdf.OutlineEntry, config: Config) !Result
const identity = contentIdentity(content);
gpa.free(content);
try verifyIdentity("rows-near-limit-worst-shape", &expected, identity, round);
- if (round >= config.warmup) try samples.append(gpa, @max(1, elapsed));
+ if (round >= config.warmup) samples[round - config.warmup] = @max(1, elapsed);
}
- return summarize("rows-near-limit-worst-shape", 1, samples.items, expected.?);
+ return summarize("rows-near-limit-worst-shape", 1, samples, expected.?);
}
fn preparedCore(path: []const u8) !*pardes.Pardes {
@@ -495,14 +495,15 @@ fn reportText(config: Config, results: []const Result) void {
std.debug.print("\nBatched rows divide elapsed time by operations/sample: cached={d}, step={d}.\n", .{ cached_batch, step_batch });
}
+const json_report_max_bytes = 16 * 1024;
+
fn reportJson(io: std.Io, config: Config, results: []const Result) void {
- var out: std.ArrayList(u8) = .empty;
- defer out.deinit(gpa);
- out.print(gpa, "{{\"benchmark\":\"pardes-pdf-sections\",\"build\":\"ReleaseFast\",\"warmup\":{d},\"reps\":{d},\"results\":[", .{
+ var storage: [json_report_max_bytes]u8 = undefined;
+ var out: std.Io.Writer = .fixed(&storage);
+ out.print("{{\"benchmark\":\"pardes-pdf-sections\",\"build\":\"ReleaseFast\",\"warmup\":{d},\"reps\":{d},\"results\":[", .{
config.warmup, config.reps,
}) catch return;
for (results, 0..) |result, i| out.print(
- gpa,
"{s}{{\"scenario\":\"{s}\",\"operations_per_sample\":{d},\"min_ns\":{d},\"median_ns\":{d},\"p90_ns\":{d},\"max_ns\":{d},\"items\":{d},\"bytes\":{d},\"checksum\":\"{x:0>16}\"}}",
.{
if (i == 0) "" else ",",
@@ -517,8 +518,8 @@ fn reportJson(io: std.Io, config: Config, results: []const Result) void {
result.identity.checksum,
},
) catch return;
- out.appendSlice(gpa, "]}\n") catch return;
- std.Io.File.stdout().writeStreamingAll(io, out.items) catch {};
+ out.writeAll("]}\n") catch return;
+ std.Io.File.stdout().writeStreamingAll(io, out.buffered()) catch {};
}
fn writeFile(path: []const u8, bytes: []const u8) !void {