How can I use a POSIX timer to determine execution time?
Once you understand POSIX timers (see POSIX timer question), it is relatively easy to use a timer to determine how long it takes to execute code. The itimerval structure should be populated with a time that is much larger than one expects for the execution (e.g. some large number of seconds). The timer_create function can be used to create the timer that will be used. Its first argument is the type of timer (see man timer_create, the types are similar to the interval timers described above) which should be chosen based upon the desired application. The second argument specifies the event handler which in our case will be NULL. Finally, a pointer to a valid timer_t object must be passed which will be populated with the id of the new timer. An itimerspec structure (which has the same it_interval and it_value fields as the itimerval structure) is populated with a duration longer than the code is expected to execute (some big number) and no interval. The timer_settime function can be used