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;
| Type | Description |
|---|---|
TPdfBenchmarkStatus | 终态,取 pbsPassed、pbsFailed 或 pbsSkipped |
TPdfBenchmarkCase | 输入路径、可选密码、增强功能标识符、显示名称,以及可选的预期语义与像素哈希 |
TPdfBenchmarkCases | TPdfBenchmarkCase 值的动态数组 |
TPdfBenchmarkOptions | 预热与测量轮数、页面与像素预算、渲染选项、哈希选择、独立重开验证门、采样间隔、取消和失败策略 |
TPdfBenchmarkCaseResult | 单个用例结果,含字节大小、页数、计时、吞吐量、工作集采样、哈希、稳定性验证门、重开验证门和失败证据 |
TPdfBenchmarkCaseResults | TPdfBenchmarkCaseResult 值的动态数组 |
TPdfBenchmarkReport | 有序的用例结果,带聚合计数器、一致性状态、JSON 导出和 CSV 导出 |
| Member | Description |
|---|---|
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 | 使用默认用例元数据和请求的选项运行文件名列表 |
| Record | Public fields |
|---|---|
TPdfBenchmarkCase | Name, EnhancementId, FileName, Password, ExpectedSemanticHash, and ExpectedPixelHash |
TPdfBenchmarkOptions | WarmupRuns, 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 实例中,且页数、语义哈希和像素哈希必须与测量输入轮次一致
当测量轮次之间哈希不一致、预期哈希不匹配、独立重开改变了语义或像素、加载或保存失败,或某个有界操作抛出错误时,该用例失败
| Field | Meaning |
|---|---|
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 | 分别报告每个已配置的语料库预期验证门 |
| Record | Public fields |
|---|---|
TPdfBenchmarkCaseResult | Name, EnhancementId, FileName, Status, ErrorText, PageCount, PagesRendered, WarmupRuns, and MeasuredRuns,以及上文列出的测量与验证门字段 |
TPdfBenchmarkReport | Results 包含有序的用例结果,Cancelled 记录终态取消 |
TPdfBenchmarkOptions.Default 启用语义与像素哈希、独立重开检查、一轮预热、三轮测量以及有界渲染TPdfBenchmarkReport.IsConformant 返回 False
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;