iticks.3c (2010 09)
i
iticks(3C) iticks(3C)
The time it takes to execute any given sequence of code, and thus the values reported by these interfaces,
will vary from machine to machine.
The behavior of
iticks_gettimes()
is unspecified if used with unbound threads.
These interfaces are intended to be used to measure small intervals (fractions of a second). If the value of
the time interval that is stored in an iticks_t object is too large, it will silently overflow the
struct
timespec or hrtime_t when it is converted.
EXAMPLES
The following code fragment measures the average cost of
gethostname():
#include <iticks.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main() {
iticks_t begin_user, end_user, total_user = 0;
iticks_t begin_sys, end_sys, total_sys = 0;
iticks_t begin_real, end_real, total_real = 0;
struct timespec user, sys, real;
char *name;
int i, count = 1000;
size_t size = sysconf(_SC_HOST_NAME_MAX) + 1;
name = (char*)malloc(size);
for (i = 0; i < count; i++) {
iticks_gettimes(&begin_user, &begin_sys, NULL, &begin_real);
(void)gethostname(name, size);
iticks_gettimes(&end_user, &end_sys, NULL, &end_real);
total_user += (end_user - begin_user);
total_sys += (end_sys - begin_sys);
total_real += (end_real - begin_real);
}
user = iticks_to_timespec(total_user / count);
sys = iticks_to_timespec(total_sys / count);
real = iticks_to_timespec(total_real / count);
printf("Avg gethostname() time:\n");
printf("\tuser:\t%ld.%09ld\n", user.tv_sec, user.tv_nsec);
printf("\tsys:\t%ld.%09ld\n", sys.tv_sec, sys.tv_nsec);
printf("\treal:\t%ld.%09ld\n", real.tv_sec, real.tv_nsec);
}
SEE ALSO
adjtime(2), getrusage(2), gettimeofday(2), pstat_getstatic(2), settimeofday(2), stime(2), time(2), gethr-
time(3).
STANDARDS CONFORMANCE
iticks_gettimes(), iticks_to_timespec(), iticks_to_hrtime(): None
2 Hewlett-Packard Company − 2 − HP-UX 11i Version 3: September 2010