An offline robot log replay can use little CPU time and still keep an operator waiting. A replay job may wait for storage, a worker, or another service before it can decode the next group of records. An elapsed-time measurement includes those pauses. A process CPU measurement counts execution charged to the process while its threads run. Both belong in a replay benchmark because they answer different questions.

Suppose a team changes how a report loads a capture. The new version may improve elapsed time while leaving the parsing cost unchanged. Another change could reduce CPU time without a visible reduction in elapsed time because an unrelated queue dominates the interval. Publishing only one of those numbers makes it hard to tell which part of the job improved.

Measure the same interval with both clocks

For a Python replay tool, the difference between two perf_counter_ns readings is elapsed time. The difference between two process_time_ns readings measures user and system CPU time charged to the current process. The nanosecond functions keep differences in integer units. Those units do not guarantee that the underlying clocks resolve every nanosecond. Microsoft documents clock resolution and measurement overhead separately for its high-resolution performance counter.

The following exercise feeds a fixed set of three synthetic record fields to a parser. It repeats the parsing operation a million times to make the active work measurable. The second pass performs the same work and includes a simulated wait before parsing. The sleep is a controlled delay in the example, with no claim about how long a real storage device or service takes.

from time import perf_counter_ns, process_time_ns, sleep

def replay(delay_seconds):

records = ("7,210", "9,360", "1,510")

elapsed_start = perf_counter_ns()

cpu_start = process_time_ns()

if delay_seconds:

sleep(delay_seconds)

total = 0

for step in range(1_000_000):

record = records[step % len(records)]

total += int(record.split(",")[1])

cpu_ms = (process_time_ns() - cpu_start) / 1_000_000

elapsed_ms = (perf_counter_ns() - elapsed_start) / 1_000_000

return total, elapsed_ms, cpu_ms

baseline = replay(0)

with_wait = replay(0.2)

assert baseline[0] == with_wait[0] == 359_999_850

for name, result in (("baseline", baseline), ("simulated wait", with_wait)):

print(name, f"{result[1]:.1f} ms elapsed",

f"{result[2]:.1f} ms process CPU")

Compare both elapsed readings and both CPU readings. In the local fixture, the wait clearly increased elapsed duration while the two CPU readings stayed much closer to each other. They need not be identical. The OS can schedule each pass differently, and actual clock accounting granularity varies by environment. For an engineering comparison, repeat both cases and record the observed distribution rather than treating a single run as a throughput claim.

Keep the scope of CPU accounting explicit

Process CPU time includes other threads in that process. If the parser runs alongside a report renderer in the same process, the CPU delta can include work done by both. If the parser runs in a child process, a measurement in the parent can show a low CPU delta while the child does substantial work. Identify which processes perform the work before interpreting a low value. When measuring multiple workers, collect their CPU deltas over the same job interval and keep the wall-clock interval as a separate metric.

A multithreaded process can accumulate more than one second of CPU time during one second of elapsed time when several threads run in parallel on multiple cores. Microsoft's process timing documentation explains this for Windows by summing execution across a process's threads. Subtracting process CPU time from elapsed time is therefore not a reliable blocked-time metric. Measure the specific queue, storage read, or service request if its wait is the quantity under investigation.

Make reports comparable across runs

Use the same capture, replay range, output checks, worker configuration, and measurement boundaries. Record whether a test parses bytes already in memory or starts from a file read. Separate cold starts from warmed runs if loading and initialization are meaningful to operators. Include a check on parsed record count or a deterministic output digest so a faster result cannot be credited to work that was accidentally skipped.

Report elapsed milliseconds per replay and process CPU milliseconds alongside the input size. If an operator cares about the delay between pressing Replay and seeing results, place the elapsed timer around that whole interval. If a developer is investigating parse cost, add timers around that stage. Keeping the two measures tied to their actual boundaries makes regressions easier to reproduce and avoids mistaking low CPU usage for a responsive replay.

Sources

Python library reference, performance counter and process CPU time

https://docs.python.org/3/library/time.html

Microsoft Win32 documentation, GetProcessTimes

https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getprocesstimes

Microsoft Win32 documentation, acquiring high-resolution time stamps

https://learn.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps