PDFium Delphi Component Docs

FPdfBenchmark 单元

单元: FPdfBenchmark
运行可重复的 PDF 性能测量和一致性验证门,且各轮次之间不共享文档、页面、表单或位图句柄

语法

function PdfBenchmarkStatusName(Status: TPdfBenchmarkStatus): string;
function RunPdfBenchmarkCorpus(const Cases: array of TPdfBenchmarkCase; const Options: TPdfBenchmarkOptions; const CancellationToken: IPdfCancellationToken = nil): TPdfBenchmarkReport;
function RunPdfBenchmarkFiles(const FileNames: array of string; const Options: TPdfBenchmarkOptions; const CancellationToken: IPdfCancellationToken = nil): TPdfBenchmarkReport;

公共类型

TypeDescription
TPdfBenchmarkStatus终态,取 pbsPassed、pbsFailed 或 pbsSkipped
TPdfBenchmarkCase输入路径、可选密码、增强功能标识符、显示名称,以及可选的预期语义与像素哈希
TPdfBenchmarkCasesTPdfBenchmarkCase 值的动态数组
TPdfBenchmarkOptions预热与测量轮数、页面与像素预算、渲染选项、哈希选择、独立重开验证门、采样间隔、取消和失败策略
TPdfBenchmarkCaseResult单个用例结果,含字节大小、页数、计时、吞吐量、工作集采样、哈希、稳定性验证门、重开验证门和失败证据
TPdfBenchmarkCaseResultsTPdfBenchmarkCaseResult 值的动态数组
TPdfBenchmarkReport有序的用例结果,带聚合计数器、一致性状态、JSON 导出和 CSV 导出

函数与记录方法

MemberDescription
PdfBenchmarkStatusName返回 TPdfBenchmarkStatus 值的稳定显示名称
TPdfBenchmarkCase.FromFile从文件路径创建用例,可带增强功能标识符和显示名称
TPdfBenchmarkOptions.Default返回预热、测量、渲染、哈希、重开验证和内存采样的有界默认值
TPdfBenchmarkCaseResult.IsPassed当用例状态为 pbsPassed 时返回 True
TPdfBenchmarkReport.PassedCount / FailedCount / SkippedCount按终态统计结果数量
TPdfBenchmarkReport.IsConformant仅在运行未被取消且所有用例通过时返回 True
TPdfBenchmarkReport.ToJson / ToCsv将完整报告序列化为 JSON 或 CSV 文本
TPdfBenchmarkReport.SaveJsonToFile / SaveCsvToFile将序列化后的报告写入 UTF-8 文件
RunPdfBenchmarkCorpus按请求的选项和取消令牌运行完整描述的基准用例
RunPdfBenchmarkFiles使用默认用例元数据和请求的选项运行文件名列表

用例与选项字段

RecordPublic fields
TPdfBenchmarkCaseName, EnhancementId, FileName, Password, ExpectedSemanticHash, and ExpectedPixelHash
TPdfBenchmarkOptionsWarmupRuns, MeasuredRuns, MaxPages, RenderWidth, RenderHeight, MaxPixelsPerPage, RenderOptions, BackgroundColor, IncludeSemanticHash, IncludePixelHash, VerifyIndependentReopen, MemorySampleIntervalMs, and StopOnFailure

测量模型

每次预热和测量轮次都会从用例路径打开全新的 TPdf 实例,通过常规的 PDFium 后端 API 加载它,渲染有界的页面子集,计算所请求的哈希,保存到内存,并释放所有句柄

首页指标合并了文档加载与首次有界页面渲染,因此它代表到达首批可用像素的时间,而不仅仅是解析器构建的时间

渲染吞吐量使用测得的页数和渲染时长,而 MaxPages、RenderWidth、RenderHeight 和 MaxPixelsPerPage 在位图分配之前约束工作量

语义 SHA-256 摘要涵盖页面顺序、页面尺寸、旋转和 UTF-16 文本,而像素 SHA-256 摘要涵盖确定性的位图尺寸和扫描线字节

启用独立重开验证后,保存的字节会被加载到第二个 TPdf 实例中,且页数、语义哈希和像素哈希必须与测量输入轮次一致

当测量轮次之间哈希不一致、预期哈希不匹配、独立重开改变了语义或像素、加载或保存失败,或某个有界操作抛出错误时,该用例失败

结果字段

FieldMeaning
InputBytes / SavedBytes源文件长度与 PDFium 保存输出的长度
LoadMilliseconds平均测得的文档加载时长
FirstPageMilliseconds平均加载加上首次有界渲染的时长
RenderMilliseconds / RenderPagesPerSecond平均有界渲染时长与由此推得的页面吞吐量
SaveMilliseconds / ReopenMilliseconds平均内存保存与独立重开验证时长
BaselineWorkingSetBytes / PeakWorkingSetBytes各测量轮次中最低的基线与最高的采样进程工作集
PeakWorkingSetIncreaseBytes相对对应轮次基线的最大采样增量
SemanticHash / PixelHash用于稳定性与语料库预期验证门的小写 SHA-256 摘要
ReopenSemanticHash / ReopenPixelHash由独立重开的保存结果计算出的同一性值
StableAcrossRuns当每次测量轮次产生相同的语义与像素同一性时为 True
IndependentReopenChecked / IndependentReopenSucceeded报告是否请求了重开验证以及重开是否成功
EquivalentAfterReopen当独立重开的保存保留页数和所选同一性值时为 True
ExpectedSemanticHashMatched / ExpectedPixelHashMatched分别报告每个已配置的语料库预期验证门

报告与结果标识字段

RecordPublic fields
TPdfBenchmarkCaseResultName, EnhancementId, FileName, Status, ErrorText, PageCount, PagesRendered, WarmupRuns, and MeasuredRuns,以及上文列出的测量与验证门字段
TPdfBenchmarkReportResults 包含有序的用例结果,Cancelled 记录终态取消

备注

示例

uses FPdfBenchmark;

var
  Cases: TPdfBenchmarkCases;
  Options: TPdfBenchmarkOptions;
  Report: TPdfBenchmarkReport;
begin
  SetLength(Cases, 1);
  Cases[0] := TPdfBenchmarkCase.FromFile('C:\Corpus\sample.pdf', 100, 'release-sample');
  Options := TPdfBenchmarkOptions.Default;
  Options.MaxPages := 8;
  Options.RenderWidth := 1024;
  Report := RunPdfBenchmarkCorpus(Cases, Options);
  Report.SaveJsonToFile('C:\Corpus\benchmark.json');
  Report.SaveCsvToFile('C:\Corpus\benchmark.csv');
end;