/* exec_time.c: check the execution time of function(s) */
/* able to measure in milli-seconds (ms) */
 
#include <stdio.h>
#include <sys/time.h>
 
void func(void);
 
int main(void) {
 
    struct timeval tv1, tv2;
 
    gettimeofday(&tv1, NULL);
    func();
    gettimeofday(&tv2, NULL);
 
    printf ("Total time = %f seconds\n",
            (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
            (double) (tv2.tv_sec - tv1.tv_sec));
 
    return(0);
}
 
void func(void) {
    int i;
    int p[10];
 
    for(i = 0; i < 3; i++) {
        printf("%d\n", p[i] = i); 
        sleep(1);
    }   
}