Guide
How to trace PDF performance in C#
Enable PerformanceTrace, run the PDF workflow, then read or write the timing summary.
The trace API is diagnostic instrumentation. It helps identify expensive parser, page-tree, extraction, or application-defined scopes during development and performance investigations.
Trace a document workflow
Reset the trace before the measured work, enable it, run the workflow, then disable tracing before printing the summary.
using ZingPDF;
using ZingPDF.Diagnostics;
PerformanceTrace.Reset();
PerformanceTrace.SetEnabled(true);
using var pdf = Pdf.Load(File.OpenRead("input.pdf"));
_ = await pdf.GetPageCountAsync();
_ = await pdf.ExtractTextAsync();
PerformanceTrace.SetEnabled(false);
Console.WriteLine(PerformanceTrace.GetSummary());
Add a custom scope
Use Measure(...) around application work that belongs next to built-in ZingPDF timings.
using (PerformanceTrace.Measure("Import.InvoiceBatch"))
{
using var pdf = Pdf.Load(File.OpenRead("invoice-batch.pdf"));
await pdf.GetPageCountAsync();
await pdf.ExtractTextAsync();
}
Enable from the environment
Set ZINGPDF_PERF_TRACE=1 before process startup to enable tracing without changing code.
set ZINGPDF_PERF_TRACE=1
Operational notes
- The trace store is process-wide and static.
- Call
Reset()between measured runs so summaries do not mix separate workloads. GetSummary(...)returns a formatted table.WriteSummary(...)writes the same data to aTextWriter.- Tracing is for diagnostics, not API-level timing guarantees.
Next step
For measured benchmark results, see the ZingPDF performance page.