사용자 도구

사이트 도구


c_exec_time
/* 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);
    }   
}
c_exec_time.txt · 마지막으로 수정됨: 2015/02/07 05:08 (바깥 편집)