2016-07-13 3 views
0

LinkedList 용 멀티 스레드 C 코드를 작성했습니다. 코드의 처리량과 대기 시간을 측정하려고합니다. 처리량을 측정하기 위해, 여기 내 코드코드 처리량 및 대기 시간 측정

clock_t begin = clock();  
    pthread_create (&t1, NULL, thread1, (void *)head); 
    pthread_create (&t2, NULL, thread2, (void *)head); 
    pthread_create (&t3, NULL, thread3, (void *)head); 
    pthread_create (&t4, NULL, thread4, (void *)head); 
    pthread_join (t1, NULL); 
    pthread_join (t2, NULL); 
    pthread_join (t3, NULL); 
    pthread_join (t4, NULL); 
clock_t end = clock(); 

입니다 그리고 내가 제대로이 두 개의 매개 변수를 측정하고 있는가

void * thread1(void * args) 

{ 
    clock_t begin = clock(); 

/* LinkedList Operations */ 

    clock_t begin = clock(); 
} 

를 다음 또는 그것을 할 다른 방법이 있으므로 대기 시간은 무엇입니까?

미리 감사드립니다.

+0

[DUP] (http://stackoverflow.com/a/5249150/5058676) – evaitl

답변

1

내 개인적인 취향이 같은 것입니다 :

struct timespec start, end; 
clock_gettime(CLOCK_MONOTONIC_RAW, &start); 
sleep(1); 
clock_gettime(CLOCK_MONOTONIC_RAW, &end); 
const uint64_t ns = (end.tv_sec * 1000000000 + end.tv_nsec) - (start.tv_sec * 1000000000 + start.tv_nsec); 
printf("elapsed %7.02f ms (%lu ns)\n", ns/1000000.0, ns);