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以預設案例中繼資料與指定選項執行檔案名稱清單

Case 與 Option 欄位

RecordPublic fields
TPdfBenchmarkCaseName、EnhancementId、FileName、Password、ExpectedSemanticHash 與 ExpectedPixelHash
TPdfBenchmarkOptionsWarmupRuns、MeasuredRuns、MaxPages、RenderWidth、RenderHeight、MaxPixelsPerPage、RenderOptions、BackgroundColor、IncludeSemanticHash、IncludePixelHash、VerifyIndependentReopen、MemorySampleIntervalMs 與 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 與 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;