cpucycles - count CPU cycles
#include <cpucycles.h> long long count = cpucycles(); long long persecond = cpucycles_persecond(); const char *implementation = cpucycles_implementation(); const char *version = cpucycles_version();
-lcpucycles. Old systems may also need
cpucycles() returns an estimate for the number of CPU cycles that have
occurred since an unspecified time in the past (perhaps system boot,
perhaps program startup).
Accessing true cycle counters can be difficult on some CPUs and
cpucycles() does its best to produce accurate
results, but selects a low-precision counter if the only other option is
cpucycles_persecond() returns an estimate for the number of CPU cycles
per second. This estimate comes from
/etc/cpucyclespersecond if that
file exists, otherwise from various OS mechanisms, otherwise from the
cpucyclespersecond environment variable if that is set, otherwise
cpucycles_implementation() returns the name of the counter in use:
cpucycles_version() returns the
libcpucycles version number as a
"20230115". Results of
should be interpreted relative to
cpucycles is actually a function pointer. The first call to
selects one of the available counters and updates the
pointer accordingly. Subsequent calls to
cpucycles() are thread-safe.
Version: This is version 2023.01.15 of the "API" web page.