time
High-accuracy timing built on C++ <chrono> clocks (system_clock for wall-clock, steady_clock for monotonic counters).
import time
start = time.perf_counter()
time.sleep(0.5)
elapsed = time.perf_counter() - startFunctions
Wall-clock (since the Unix epoch):
time()— seconds as adouble.time_ns()— nanoseconds as along long.
Monotonic (never runs backwards):
monotonic()/monotonic_ns()— monotonic seconds / nanoseconds.perf_counter()/perf_counter_ns()— highest-resolution monotonic counter.
Other:
process_time()— CPU time consumed by this process, in seconds.sleep(seconds)— suspend the current thread for a (fractional) duration.
Per-function docs (parameters, runtime complexity, heap behavior) are in time.hpp. Tested in ../tests/time_test.cpp; ASan + Valgrind clean via the QA gate (security/run-valgrind.sh).
Functions
Wall-clock time.
Returns fractional seconds since the Unix epoch (1970-01-01 UTC) from the system clock; because it follows real time, it can jump forward or backward when the clock is adjusted (NTP, manual changes) and is not suitable for measuring elapsed intervals.
seconds since the Unix epoch (system_clock).
O(1) time.
none.
CheatahTime.WallClockIsRecentTimeCompileRun.TimeStdlibE2E.TimeWall-clock time.
Same wall clock as time but returned as an integer count of nanoseconds since the Unix epoch, avoiding the precision loss of double seconds; it shares the same caveat that the system clock can be stepped backward.
nanoseconds since the Unix epoch (system_clock).
O(1) time.
none.
CheatahTime.WallClockIsRecentTimeCompileRun.TimeNsStdlibE2E.TimeMonotonic clock; never runs backwards.
Returns fractional seconds from steady_clock, which advances steadily and is immune to system-clock adjustments, making it the right choice for timing intervals; its zero point is unspecified, so only differences are meaningful.
seconds from steady_clock.
O(1) time.
none.
TimeCompileRun.MonotonicStdlibE2E.TimeMonotonic clock; never runs backwards.
Same monotonic steady_clock as monotonic but as an integer nanosecond count, preserving full precision; only differences between readings have a defined meaning.
nanoseconds from steady_clock.
O(1) time.
none.
TimeCompileRun.MonotonicNsStdlibE2E.TimeHighest-resolution monotonic counter.
Intended as the finest-grained clock for benchmarking; in this build it is backed by the same steady_clock as monotonic, so it is monotonic with an unspecified origin and should be used only for elapsed-time measurements.
seconds from steady_clock.
O(1) time.
none.
CheatahTime.PerfCounterAdvancesTimeCompileRun.PerfCounterStdlibE2E.Time SystemApps.EventLogHighest-resolution monotonic counter.
Nanosecond-precision form of perf_counter, backed by steady_clock; like the other monotonic readings, only the difference between two calls is meaningful.
nanoseconds from steady_clock.
O(1) time.
none.
TimeCompileRun.PerfCounterNsStdlibE2E.TimeCPU time consumed by this process.
Returns processor time used by the program (via std::clock / CLOCKS_PER_SEC), not wall-clock time, so it excludes time spent sleeping or blocked and may grow faster than real time across multiple threads.
seconds of CPU time (std::clock).
O(1) time.
none.
CheatahTime.ProcessTimeNonNegativeTimeCompileRun.ProcessTimeStdlibE2E.TimeSuspend the calling thread.
Blocks the current thread for at least seconds (fractional values are honored); the OS may sleep slightly longer due to scheduling, and a non-positive duration returns essentially immediately.
seconds | duration to sleep (fractional). |
O(1) plus the sleep wait.
none.
blocks only the calling thread; other threads keep running.
TimeCompileRun.SleepStdlibE2E.Time SystemApps.EventLog